use Benchmark; push @lines, ((' ' x int rand 12) . (int rand 60000) . (' ' x int rand 2)) for 1..10000; @pattern_list = qw(12345 12346 20034 8787 31337 31338 54320 54321); my $bad_ports = '\b(?:12345|12346|20034|8787|31337|31338|54320|54321)\b'; timethese( 100, { 'qr' => 'with_qr', '/o' => 'with_o' }); sub with_qr { foreach $pattern (@pattern_list) { my $re = qr/\b${pattern}\b/; foreach $line (@lines) { $line =~ /$re/; } } } sub with_o { my $found = 0; for(@lines){ (/\b(?:$bad_ports)\b/o); } }