use strict; use warnings; $x = 0; # syntax error: $x has not been declared my $y = 1; # ok, $y is "in scope" for remainder of file { my $y = 2; # a different $y, scope limited to this block print $y, $/; # you cannot "see" the "outer" instance of $y sub foo { $y--; print "the inner \$y is now $y\n"; } foo(); } print $y, $/; # this is the "outer" $y my $x = 3; # ok: $x is in scope for remainder of file my $y = 4; # warning: "my" declaration masks earlier declaration in same scope print $y,$/; foo();