in reply to Debugging in packages

If this is in a module, i usually add a _debug key to my blessed hash and use a function with a name similar to dbg("Message"). All this function does is :
sub dbg { my ($self,$msg) = @_; return if (! $self->{_debug}); print STDERR "[DEBUG] : $msg\n"; }
And, a simple accessor method like :
sub debug { my ($self,$val) = @_; $self->{_debug} = $val if (defined $val); $self->{_debug}; }
While this all may seem a bit elaborate, it is excedingly useful to have as a standard for every module. If the $main::DEBUG is the approach you prefer, there is always more than one way to do it, and changing dbg to the following would work :
sub dbg { my $msg = shift; print "[DEBUG] : $msg\n" if ($main::DEBUG); }

OH, a sarcasm detector, that’s really useful