foreach $string (@idstring) { chomp($string); if ($msg =~ m/.*\Q$string\E.*/i) { print "$string found"; last; } }