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();