#! perl -w -l print $]; tie $_, 'MyTie'; $_ = 123; { local $_ = 456; print; } print; { package MyTie; sub TIESCALAR { my $class = shift; my $scalar; return bless \$scalar, $class; } sub FETCH { my $this = shift; local $\ = "\n"; print "FETCH from $this: $$this"; return $$this; } sub STORE { my $this = shift; my $value = shift; local $\ = "\n"; print "STORE to $this: $value"; $$this = $value; } sub DESTROY { my $this = shift; local $\ = "\n"; print "DESTROY $this"; } sub UNTIE { my $this = shift; local $\ = "\n"; print "UNTIE $this"; } }