package MyPkg; my @Instances; # Visibility restricted to package by lexical declaration sub new { my $self = shift; my $opts = ref $_[0] ? shift : { @_ }; push @Instances, { %$opts }; return bless \(my $me = $#Instances), $self; } sub getScore { my $self = shift; return $Instances[$$self]->{score}; }