http://qs321.pair.com?node_id=529740


in reply to How Do I Bundle Perl Modules and Their Tests Into the Same File?

Try this:

package abc; # ... package main; sub test_me { # test code here } test_me unless defined caller;
Like python, if the module is used or required test_me will not be executed. If you run the module using perl Module.pm, the code in test_me will be executed. Update: Just realized BrowserUK posted a very similar solution above...