use Benchmark(cmpthese); cmpthese(100_000, { 'a' => sub { $_ = 'this that this those this these.'; $a = () = /this/g; }, 'b' => sub { $_ = 'this that this those this these.'; $a++ while(s/this//); } });