use strict; use Benchmark qw/ cmpthese timethese /; my($head, $tailg, $tailb, $test, $fill) = ("", "", " $head (?:(?!$tailg).)* $test ) (?:(?!$tailg).)* $tailg }sxio; my $trial; for my $bool (qw/ g b /) { my $tail = ($bool eq 'g') ? $tailg : $tailb; for my $cut (qw/ cut uncut /) { my $re = ($cut eq 'cut') ? $recut : $reuncut; for my $count (1, 10, 100, 1000) { my $str = join '', $head, $fill, $test x $count, $fill, $tail; $trial->{"$cut$count$bool"} = sub { die if ($bool eq 'g') ^ ($str =~ $re); }; } } } timethese(-1, $trial);