#!perl use strict; use warnings; use Benchmark qw(:all); my $foo; timethese('50000000', { 'test_1' => sub { $foo = 1; }, 'test_2' => sub { my $bar = 1; }, }); 1; __END__ fred@fishman ~ $ perl scope.pl Benchmark: timing 10000000 iterations of test_1, test_2... test_1: 0 wallclock secs ( 1.03 usr + 0.01 sys = 1.04 CPU) @ 9615384.62/s (n=10000000) test_2: 2 wallclock secs ( 1.38 usr + 0.01 sys = 1.39 CPU) @ 7194244.60/s (n=10000000) fred@fishman ~ $ perl scope.pl Benchmark: timing 50000000 iterations of test_1, test_2... test_1: 6 wallclock secs ( 5.19 usr + 0.01 sys = 5.20 CPU) @ 9615384.62/s (n=50000000) test_2: 6 wallclock secs ( 6.51 usr + 0.00 sys = 6.51 CPU) @ 7680491.55/s (n=50000000)