use Benchmark; use vars qw/$a $b $c/; ($a, $b, $c) = qw/bar baz foo/; timethese(shift || 500000, { lookbehind => sub { local $_ = "foobarquux"; s/(?<=$c)$a/$b/g }, chromatic => sub { local $_ = "foobarquux"; s/($c)$a/$1$b/g }, chromatic2 => sub { local $_ = "foobarquux"; s/$c$a/$c$b/g }, substr => sub { local $_ = "foobarquux"; while ((my $p = index($_, "$c$a"))>=0) { substr($_, $p+length($c), length($a), $b); } }, });