use Benchmark qw( cmpthese timethese ); my @alphabet = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z' ); my $h = horrid_rx(1_000); my $qr_h = qr/$h/; my $qr_ho = qr/$h/o; my $s = join q{}, map { $alphabet[ rand @alphabet ] } 1 .. 1_000; my $matchiness = ( $s =~ /$h/ ) ? 'matches' : 'does not match'; print "horrid rx $matchiness string\n"; my $loops = 1_000; cmpthese( -2, { '//' => sub { $s =~ /$h/ for (1..$loops) }, '/o' => sub { $s =~ /$h/o for (1..$loops) }, 'qr' => sub { $s =~ $qr_h for (1..$loops) }, 'qr/o' => sub { $s =~ $qr_ho for (1..$loops) }, } ); sub horrid_rx { my ($n) = @_; my @quant = ( '*', '?', '+', '{0,1}', ); my $out; for ( 1 .. $n ) { $out .= $alphabet[ rand @alphabet ]; $out .= $quant[ rand @quant ]; } return $out; }