{ package MY; use Scalar::Util 'blessed'; sub AUTOLOAD { my($meth) = $AUTOLOAD =~ /::(\w+)$/; print "autoloading: $AUTOLOAD\n"; *{"MY::$meth"} = sub { goto &{(blessed($_[0])."::MY")->can($meth)} }; goto &{"MY::$meth"}; } } use strict; { package foo; sub foo::MY::that { print "that(): I'm in ", __PACKAGE__, $/; } sub this { print "this(): I'm in ", __PACKAGE__, $/; $_[0]->MY::that; } } { package bar; sub bar::MY::that { print "that(): I'm in ", __PACKAGE__, $/; } sub this { print "this(): I'm in ", __PACKAGE__, $/; $_[0]->MY::that; } } my $foo = bless [], 'foo'; $foo->this; my $bar = bless [], 'bar'; $bar->this; __output__ this(): I'm in foo autoloading: MY::that that(): I'm in foo this(): I'm in bar that(): I'm in bar