use Carp qw/croak/; BEGIN { my $logger; sub callback { my $coderef = shift; croak "$coderef is not a code reference, cannot use as a callback.\n" unless ref($coderef) eq 'CODE'; $logger = $coderef; } callback( sub { print STDERR "Executing $_[0]!\n" } ); sub logCall { &$logger( @_ ); } } #### Test::foo(); Devel::TraceMethods::callback( sub { print STDERR "called $_[0].\n" } ); Test::bar(); Test::blah(); __END__ gives: Executing foo! called bar. called AUTOLOAD. Can works!