sub foo { trace enter; #logs entry into the sub if loglevel is 'trace' eval { sub_that_might_die(shift @_); }; if ($@) { debug caught; #logs catching of exception if loglevel is 'debug' warn $@; return; } trace leave; #logs departure from sub if loglevel is 'trace' }