in reply to Re: searching through array for multiple patterns
in thread searching through array for multiple patterns

in the latter case you don't need to continue the loop after you found a match. Thus I'd do it this way:
#use a flag to indicate a match my $found = 0; foreach (@commands_run) { if($_ =~m/clock/) { $found++; last; # we have a match, exit loop } } $found ? print "\n Test -- found pattern -- \n" : print "\n Test -- did not find pattern -- \n";
of course in this case you can omit the $found ? print ...: print ..; part:
foreach (@commands_run) { if($_ =~m/clock/) { print "found pattern\n"; last; # we have a match, exit loop } }