#!/usr/bin/perl -w package Foo; use strict; sub AUTOLOAD { no strict qw(refs vars); my $pkg = __PACKAGE__; $AUTOLOAD =~ s/${pkg}:://; return if $AUTOLOAD eq 'DESTROY'; if(exists $_[0]->{$AUTOLOAD}) { no strict 'refs'; *{$AUTOLOAD} = sub { $_[1] ? $_[0]->{$AUTOLOAD} = $_[1] : $_[0]->{$AUTOLOAD}; } } else { die "Can't locate object method \"$AUTOLOAD\" via package \"$pkg\""; } &{$AUTOLOAD}(@_); } sub new { bless {foo => "bar"}, ref($_[0]) || $_[0]; } package main; use strict; my $foo = new Foo; print $foo->foo, "\n"; print $foo->foo("bas"), "\n"; print $foo->foo, "\n";