:::::::::::::: match.txt :::::::::::::: :::::::::::::: match1.pl :::::::::::::: #!/usr/bin/perl -w # match1.pl use strict; my $found = 0; $_ = "Nobody wants to hurt you... 'cept, I do hurt people sometimes, Case."; my $sought = "people"; foreach my $word (split) { if ($word eq $sought) { $found = 1; last; } } if ($found) { print "Hooray! Found the word 'people'\n"; } :::::::::::::: match2.pl :::::::::::::: #!/usr/bin/perl # match2.pl use strict; $_ = "Nobody wants to hurt you... 'cept, I do hurt people sometimes, Case."; if ($_ =~ /people/) { print "Hooray! Found the word 'people'\n"; } :::::::::::::: match3.pl :::::::::::::: #!/usr/bin/perl -w # match3.pl use strict; $_ = "Nobody wants to hurt you... 'cept, I do hurt people sometimes, Case."; if (/I do/) { print "'I do' is in that string.\n"; } if (/sometimes Case/) { print "'sometimes Case' matched.\n"; } :::::::::::::: match4.pl :::::::::::::: #!/usr/bin/perl -w # match4.pl use strict; my $test1 = "The dog is in the kennel"; my $test2 = "The sheepdog is in the field"; if ($test1 =~ / dog/) { print "This dog's at home.\n"; } if ($test2 =~ / dog/) { print "This dog's at work.\n"; } :::::::::::::: match5.pl :::::::::::::: #!/usr/bin/perl -w # match5.pl use strict; $_ = "Nobody wants to hurt you... 'cept, I do hurt people sometimes, Case."; if (/case/) { print "I guess it's just the way I'm made.\n"; } else { print "Case? Where are you, Case?\n"; } :::::::::::::: matchtest1.pl :::::::::::::: #!/usr/bin/perl -w # matchtest1.pl use strict; $_ = q("I wonder what the Entish is for 'yes' and 'no'," he thought.); # Tolkien, Lord of the Rings print "Enter some text to find: "; my $pattern = ; chomp($pattern); if (/$pattern/) { print "The text matches the pattern '$pattern'.\n"; } else { print "'$pattern' was not found.\n"; } :::::::::::::: matchtest2.pl :::::::::::::: #!/usr/bin/perl -w # matchtest2.pl use strict; $_ = '1: A silly sentence (495,a) *BUT* one which will be useful. (3)'; print "Enter a regular expression: "; my $pattern = ; chomp($pattern); if (/$pattern/) { print "The text matches the pattern '$pattern'.\n"; print "\$1 is '$1'\n" if defined $1; print "\$2 is '$2'\n" if defined $2; print "\$3 is '$3'\n" if defined $3; print "\$4 is '$4'\n" if defined $4; print "\$5 is '$5'\n" if defined $5; } else { print "'$pattern' was not found.\n"; }