package Foo::Bar; use strict; use vars qw/$AUTOLOAD/; sub AUTOLOAD { my ($self) = @_; #Don't use shift as we need to preserve @_ my ($meth) = $AUTOLOAD =~ /(\w+)$/; # Simple example: getter and setter for hash members # Note that the eval is here to stop the sub becoming a closure on $meth my $acc = eval qq( sub { my \$self = shift; \@_ ? \$self->{$meth}=shift : \$self->{$meth}; } ); { no strict 'refs'; *$AUTOLOAD = $acc; } goto $acc; }