use Benchmark qw(cmpthese); my $end = 500_000; cmpthese( -1, { plain => sub { my $total; for(1..$end) { $total += 1 / $_; } $total; }, sub => sub { my $total; for(1..$end) { $total += reciprocal($_); } $total; }, do => sub { my $total; for(1..$end) { $total += do { 1 / $_ }; } $total; }, do_var => sub { my $total; for(1..$end) { $total += do{ my $int = $_; 1 / $int }; } $total; }, } ); sub reciprocal { my ($int) = @_; 1 / $int; } __END__ Rate sub do_var plain do sub 6.60/s -- -49% -72% -72% do_var 12.9/s 95% -- -46% -46% plain 23.9/s 261% 85% -- 0% do 23.9/s 261% 85% 0% --