in reply to Making debug a little more intelligent

You might want to take a look at one of the existing logging modules on CPAN. For example, Log::Log4perl, is fairly simple and gives you lots of flexibility.

If you don't go that route I would consider using the constant module, rather than the lexical $debug. For example:

use constant DEBUGGING => 2; ... print DEBUG "foo\n" if DEBUGGING >=2; ... print DEBUG "moo\n" if DEBUGGING;

The advantage of using the constant module is that the compiler can optimise out the debugging statements if DEBUGGING is false - potentially saving time and space.