package Wrapper; use vars '$AUTOLOAD'; sub new { my $class = shift; $class = ref($class) || $class; my $obj = shift; my $self = \$obj; bless($self, $class); return $self; } sub AUTOLOAD { my $self = shift; return if $AUTOLOAD =~ /::DESTROY/; $AUTOLOAD =~ s/.*:://; no strict 'refs'; print "Do something interesting here.\n"; return $$self->$AUTOLOAD(@_); } package main; # as before my $wm = WordMatch->new("hi"); print $wm->match("[hi] how are you?"), "\n"; print $wm->match("hi how are you?"), "\n"; # our new version my $wm2 = Wrapper->new(WordMatch->new("Hello")); print $wm2->match("[Hello] little girl"), "\n";