package redefine; use warnings; use strict; my @redefines = qw( module::function foo::bar ); sub import { my $class = shift; my $caller = caller; no strict 'refs'; no warnings qw/redefine/; for my $sym (@redefines) { "unqualify" subs (my $sub = $sym) =~ s/.*:://; if ( ${$caller.'::'}{$sub} && *{$caller.'::'.$sub}{CODE} eq *$sym{CODE} ) { *{$caller.'::'.$sub} = \&$sub; } *{$sym} = \&$sub; } } sub function { package module; print "new\n"; }; sub bar { package foo; print "in bar\n"; } 1;