in reply to main and external script
Sorry, I don't have an answer to your question. However, I do have a tip:
When including Perl files without a package, you should use do, not require or use.