in reply to How to call a perl function without its context?

There is no easy way to eliminate all variables that a function has closed over. Most likely, you can get at the list of closed over variables using PadWalker, and you can reassign these variables too, using the set_closed_over function. But the variables themselves cannot be eliminated.

Also, your use of "local variables" is confusing, because Perl has the local keyword. I think you mean "lexical variables declared within the function scope".

Maybe you can tell us what kind of problem you are trying to solve. Maybe the local keyword already solves most of your problems?