package R; # Just to demonstrate a variable in another package my $R = 10; package main; # Just to prove we are "executing" in a different package my $subcode = "sub { local \$_; package R; print $R}"; my $subref = eval $subcode; &$subref;