{package Dog; sub new { my $class = shift; bless {Name=>'Spot', Color=>"black"}, $class; } #For auto generating the getters: sub AUTOLOAD { my $self = shift; our $AUTOLOAD; my %methods = ( color => undef, name => undef, ); if ($AUTOLOAD =~ /::(\w+)\z/ and exists $methods{$1} ) { my $data_name = ucfirst $1; { no strict 'refs'; *{$AUTOLOAD} = sub { $self->{$data_name} }; } goto &{$AUTOLOAD}; } else { use Carp; croak "No method named $AUTOLOAD"; } } } my $dog = Dog->new; say $dog->name; say $dog->color;