package MyClass; { # we make an attribute hash private to the foo method my %foo; sub foo { my $self = shift; $foo{$self} = shift if @_; return $foo{$self}; }; }; sub bar { my $self = shift; # so we can only access %foo using method foo here print $self->foo; };