use Benchmark qw(cmpthese); ## take the results with a grain of salt, mmmkay? cmpthese(-15, { predeclare => sub { my $x = {}; $x->{foo} = "bar" x 20 }, nodeclare => sub { my $x; $x->{foo} = "bar" x 20 } }); __output__ Benchmark: running nodeclare, predeclare, each for at least 15 CPU seconds... nodeclare: 24 wallclock secs (15.33 usr + 0.00 sys = 15.33 CPU) @ 110465.75/s (n=1693440) predeclare: 18 wallclock secs (15.58 usr + 0.02 sys = 15.60 CPU) @ 89620.83/s (n=1398085) Rate predeclare nodeclare predeclare 89621/s -- -19% nodeclare 110466/s 23% -- #### my $foo = "a string"; print "\$foo is $foo\n"; ## this $foo only lasts to the end of the for loop scope for my $foo (1..3) { print "\$foo is $foo\n"; } print "\$foo is $foo\n"; __output__ $foo is a string $foo is 1 $foo is 2 $foo is 3 $foo is a string