sub debug ($) {0;} # constant subroutine gets inlined for speed sub set_debug { # set your options... no warnings; *{My::Package::debug}{SUB} = sub { # your debugging subroutine goes here } }