package auto; sub new { my $invocation = shift(); my $class = ref($invocation) || $invocation; my $self = { A => 1, B => 2 }; my $bless = bless($self, $class); return $bless; } sub DESTROY {}; sub AUTOLOAD { my $self = shift(); our $AUTOLOAD; for($AUTOLOAD) { /.*::(.*)/; $key = $1; } if (grep {/^$key$/} keys %{$self->{$key}}) { if (scalar(@_)) { $self->{$key} = shift(); } else { return $self->{$key}; } } else { for($key) { /(.*)_val/ and do { if(grep{/$1/} keys(%{$self})) { if (scalar(@_)) { $self->{$1} =(shift()); } else { return $self->{$1}; } } last; }; } } } 1;