$tofind = "some string"; while() { push @list, $_; } # Make a compiled list with qr @clist = map qr/$_/, @list; # Now run the two lists foreach (@list) { print "Found $tofind\n", last if($tofind =~ /$_/); } foreach (@clist) { print "Found $tofind\n", last if($tofind =~ /$_/); }