You mentioned logging but didn't say how you were doing it. I encourage you to take a look at utilizing Log::Log4perl. It doesn't help you with your main question, but it really helps manage logging and messaging during run time.
Comment on Re: How to capture (intercept) output (warnings) of a module