$\ = "\n"; # automatically add newlines to output $Foo = 4; # create the var print '*Foo{SCALAR} = ', *Foo{SCALAR}; # print the glob entry my $x = \$Foo; # make a reference... which is print '$x = ', $x; # the same as the glob entry.. duh $$x = 5; # change via reference print '$Foo = ', $Foo; # var has changed my $y; print "Enter scope"; { local $Foo = 42; # let the magic begin! print '*Foo{SCALAR} = ', *Foo{SCALAR}; # it's different! $y = \$Foo; # take a ref to this new thing print '$y = ', $y; # the same as the *new* glob entry print '$Foo = ', $Foo; # foo is 42 print '$$x = ', $$x; # print old var via reference.. unchanged print '$$y = ', $$y; # print new var via reference.. it's 42 $$x = 6; # change via reference to *old* print '$Foo = ', $Foo; # nothing happened to the local one! # but wait... } print "Exit scope"; print '*Foo{SCALAR} = ', *Foo{SCALAR}; # old glob entry is back print '$Foo = ', $Foo; # and we changed this one via $x earlier! print '$y = ', $y; # now the last remaining reference to local var print '$$y = ', $$y; # still 42