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


in reply to require, globals, and some various mayhem

What you're missing is that those aren't globals. Variables declared with my() are lexical, not global, and the reason it works when the subs are defined within the same script is that the lexical variables and the sub are in the same scope.

What you should do is pass the variables to the sub. However, your globals approach will work, provided you declare the variables with our() instead of my().