... # some scope # pass coderef, returns coderef rebound to this scope *rebind_here = sub { use B::Deparse (); ref $_[0] eq "CODE" or die "expected coderef"; eval("sub ".B::Deparse->new->coderef2text($_[0])); } ... # some other scope $new_coderef = &rebind_here($old_coderef);