package Apache::LogParser; use Carp; sub new { my ( $class ) = @_; my $self = { hits => { foo => 1, bar => 2 }, misses => { baz => 3, boo => 4 }, }; # we need to bless our hash into our class! return bless $self, $class; } # define an accessor, use wantarray to return hash or hash ref depending on context sub hits { my ( $self ) = @_; return wantarray ? %{$self->{hits}} : $self->{hits}; } # define a generic accessor using autoload to save lots of accessor code # you could also make this a set/get method, it is just a get as shown sub AUTOLOAD { my ( $self ) = @_; my ( $func ) = $AUTOLOAD =~ m/::([^:]+)$/; if ( exists $self->{$func} ) { return wantarray ? %{$self->{$func}} : $self->{$func}; } else { confess "Unknown method $func\n"; } } use Data::Dumper; my $al = new Apache::LogParser; my %hits = $al->hits; print Dumper \%hits; print Dumper scalar($al->misses); $al->no_existing_method;