package Person; use strict; use warnings; use diagnostics; my $Census = 0; sub new{ my $proto = shift; my $class = ref($proto) || $proto; my $self = {}; $self->{NAME} = undef; # "private" data $self->{"_CENSUS"} = \$Census; bless ($self, $class); ++ ${ $self->{"_CENSUS"} }; return $self; } sub name { my $self = shift; if (@_) { $self->{NAME} = shift } return $self->{NAME}; } 1; # so the require or use succeeds sub DESTROY { my $self = shift; print $self->{NAME}." dies now: life was nice\n"; -- ${ $self->{"_CENSUS"} }; }