{ package A; local *x = sub { die "aaa" }; #run tests ... } # &x reset after leaving block #### $old_coderef = \&x; # run tests ... # do what you want ... # (but think about the omen ;-) *x = $old_coderef;