use strict; use warnings; use 5.010; use Benchmark qw[ cmpthese ]; use List::Util qw[ shuffle ]; our @terms = qw[ the quick brown fox jumps over the lazy dog ]; our $re = join'', map "(?=^.*$_)", @terms; $re = qr/$re/; our @lines = map join( ' ', shuffle @terms), 1 .. 100; push @lines, ( 'every good boy deserves food' ) x 100; my $line = join '&&', map {"/$_/"} @terms; our( $a, $b, $c ) = (0) x 3; cmpthese -1, { a=>q[ /$re/ and ++$a for @lines; ], b=>q[ for my $str ( @lines ) { !grep( $str !~ /$_/, @terms) and ++$b; } ], c=>qq [$line && ++\$c for \@lines;], }; say "$a:$b:$c"; __END__ Rate b a c b 39.8/s -- -95% -97% a 807/s 1927% -- -36% c 1254/s 3051% 55% -- 109400:4800:243000