use warnings; use strict; { package Spin::Command::spin; sub run { print "Bar<<".shift.">>\n"; } sub func { run("Foo:".shift); } } my $func = \&Spin::Command::spin::func; use B::Deparse; my $deparse = B::Deparse->new; print "<<",$deparse->coderef2text($func),">>\n"; sub other_run { print "Quz[[".shift."]]\n"; } my $func_other_run = sub { no warnings 'redefine'; local *Spin::Command::spin::run = \&main::other_run; $func->(@_); }; $func->("Hello"); # prints "Bar<>" $func_other_run->("World"); # prints "Quz[[Foo:World]]"