use strict; use warnings; my $val = 1; print "my own scope: $val\n"; { my $val = 2; print "my own scope: $val\n"; { print "inherit: $val\n"; # this is another scope, but doesn't have an override of the val=2 $val = 2.5; print "edit: $val\n"; # now it's a different value } print "keep the value edited: $val\n"; # which it keeps here { my $val = 3; # this is another scope with it's own lexical $val, so the previous $val's are invisible to me print "my own scope: $val\n"; } my $val = -2; # warning: masks earlier declaration in same scope print "when scopes collide: $val\n"; } print "back in original file scope: $val\n";