$old_coderef = \&x; # run tests ... # do what you want ... # (but think about the omen ;-) *x = $old_coderef;