http://www.perlmonks.org?node_id=992890


in reply to How to do perl -c inside perl?

The solution that satisfies the most is to wrap the code I want to try inside a eval "sub {$code}".

Starting with commit 0067b6c, I have been using this approach and have been most pleased with it. It will catch things like prototype mismatches which is not strictly a syntax checking thing. That may be good or bad depending on your needs.

This code: $x=1; __END__ $y= will be tagged as a syntax error when it is not. But this is not of great concern to me.