sub foo { my $foo = 1; if (1 == 1) { # just to demonstrate the point $foo++; # inside foo, works fine } print $foo; bar(); } sub bar { print $foo; # outside foo, blows up } foo(); #### sub foo { local $foo = 1; if (1 == 1) { # just to demonstrate the point $foo++; } print "From foo: $foo\n"; bar(); } sub bar { # this variable will be set to whatever it was # before we got called print "From bar: $foo\n"; } $foo = 5; foo(); bar();