use strict; use warnings; my @commands_run = qw(first second clock fourth); #join all elements of the array my $all_commands = join '#', @commands_run; if ($all_commands =~m/clock/) { print "\n Test -- found pattern -- \n"; } else { print "\n Test -- did not find pattern -- \n"; } #use a flag to indicate a match my $found = 0; foreach (@commands_run) { if($_ =~m/clock/) { $found++; } } $found ? print "\n Test -- found pattern -- \n" : print "\n Test -- did not find pattern -- \n";