Mega Code Archive

 
Categories / Perl / String
 

Split string into separate words, and then test to see if each word is the one were looking for

#!/usr/bin/perl use warnings; use strict; my $found = 0; $_ = "string... 'i'"; my $sought = "people"; foreach my $word (split) {     if ($word eq $sought) {         $found = 1;         last;     } } if ($found) {     print "Hooray! Found the word 'people'\n"; }