A module is intended to be a library of routines but not main programs. The code after the BEGIN block and before 'sub app_error' is anonymous and therefore only runs when the module is run (incorrectly) as a main program. To run that code from another script it needs to be placed inside a method like sub new { your code } and called by the name of the new method.