use strict; use warnings; use Benchmark qw(cmpthese); my $string = '0' x 13; cmpthese( 0, { 'eq_loop_string' => q{ for ( 0 .. 12 ) { next if ( $string eq '0000000000000' ); $_ = ( $string =~ tr/1/1/ ); } }, 'eq_loop_sub' => sub{ for ( 0 .. 12 ) { next if ( $string eq '0000000000000' ); $_ = ( $string =~ tr/1/1/ ); } }, 'tr_loop_string' => q{ for ( 0 .. 12 ) { next unless ( $_ = ( $string =~ tr/1/1/ ) ); } }, 'tr_loop_sub' => sub{ for ( 0 .. 12 ) { next unless ( $_ = ( $string =~ tr/1/1/ ) ); } }, 'eq' => q($string eq '0000000000000';), 'tr' => q($string =~ tr/1/1/;), } );