use strict; use warnings; use Benchmark qw(cmpthese); my $string = '0'x13; cmpthese(0, { 'eq_loop' => q(for (0..12) { next if ($string eq '0000000000000'); $_ = ($string =~ tr/1/1/); }), 'tr_loop' => q(for (0..12) { next unless ($_ = ($string =~ tr/1/1/)); }), 'eq' => q($string eq '0000000000000';), 'tr' => q($string =~ tr/1/1/;), });