in reply to typeglob & my | our

The fact that you changed the variable associated with package variable %main::foo has no bearing on the contents of lexical var %foo.

use strict; use warnings; my $hashref = { "key" => "value" }; my %foo; local *foo = $hashref; # Short for *main::foo printf("keys=%d\n", scalar(keys(%main::foo))); # keys=1 printf("keys=%d\n", scalar(keys(%foo))); # keys=0