use warnings; use strict; my $fileText = <>> OP version\n"; open my $infile, "<", \$fileText; while (my $line = <$infile>) { next if $line !~ $comb; for my $target(@argList) { next if $line !~ $target; print "Matched '$target' in: $line"; } } print "\n>>> Grandfather version\n"; open $infile, "<", \$fileText; while (my $line = <$infile>) { print "Matched '$1' in: $line" while $line =~ /($comb)/g; } #### >>> OP version Matched 'regexes' in: I'm trying to search for several regexes in some long files. To speed things up, Matched '^I' in: I'm trying to search for several regexes in some long files. To speed things up, Matched '^I' in: I tried first checking a combined regex, to see if any of them matches the line. Matched 'regexes' in: This seems to speed things up, at least when the regexes are just plain words. Matched 'regexes' in: But: If I try input regexes which are anchored ("^word"), then suddenly it's Matched 'that' in: (I could rewrite ^aaa|^bbb|^ccc as ^(aaa|bbb|ccc), but it might be that only >>> Grandfather version Matched 'I' in: I'm trying to search for several regexes in some long files. To speed things up, Matched 'regexes' in: I'm trying to search for several regexes in some long files. To speed things up, Matched 'I' in: I tried first checking a combined regex, to see if any of them matches the line. Matched 'regexes' in: This seems to speed things up, at least when the regexes are just plain words. Matched 'regexes' in: But: If I try input regexes which are anchored ("^word"), then suddenly it's Matched 'that' in: (I could rewrite ^aaa|^bbb|^ccc as ^(aaa|bbb|ccc), but it might be that only