Badger::Debug

package Your::Forager;
use base 'Badger::Base';
use Badger::Debug default => 0;

our $MESSAGES = {
    foraging => 'Foraging in the %s for %s',
};

sub forage {
    my ($self, $where, $what) = @_;
    $self->debug_msg( foraging => $where, $what ) if DEBUG;
    # ... do some foraging...
}
Thus Spake Andy:

Badger::Debug can take care of this for you. Tell it the default debugging value and it will do both of the previous steps. It sets $DEBUG (unless already defined) and then creates a DEBUG constant set to whatever value $DEBUG has. Now you can have both the runtime efficiency of a constant and the convenient switch-off-and-on-ability of a package variable.