$_ = 'hi'; my $code = sub { print $_->{blah} . "\t" . $_->{moo} . "\n" }; Bar::hi($code); print $_ . "\n"; # prints 'hi' package Bar; sub hi { my $coderef = shift; local $_ = { 'foo' => 2, 'blah' => 5, 'moo' => 'blah' }; &$coderef; # prints '5 blah' }