You could have a look at
http://search.cpan.org/~grian/Eval-Compile-0.10/lib/Eval/Compile.pm but note the caveat mentions not being threadsafe, so I can't be sure if what funny side effects you might get. Having said that it seems to work fine for me.