use strict; use warnings; use Carp; package main; sub debug { my ($pkg) = caller; { no strict 'refs'; return unless ${ "${pkg}::DEBUG_FLAG" }; } carp "@_"; } package My_First; our $DEBUG_FLAG = 1; ::debug( "Print " . __PACKAGE__ ); # prints package My_Second; our $DEBUG_FLAG = 0; ::debug( "Print " . __PACKAGE__ ); # doesn't print