in reply to Using an "outer" lexical in a sub?

There is something called package scope. In each point in time, perl code is in exactly one package scope.

There is something pretty different called lexical scope. In each point of time, perl code can be in one or more lexical scopes. Lexical scopes are distributed into nested lexical scopes.

my $outer = 1; # lexical file scope { my $inner = 1; # here I can see both $inner and $outer # as $outer is "inherited" from the outer # lexical scope { my $inner = 2; # this $inner is completely different $inner # than the $inner in the direct outer scope # but still I can see $outer } # now I can see $inner that is equal to 1 } # now I can see only $outer
For additional reading, I recommend perlsub, namely "Private Variables via my()".