... preamble as before use strict; my $_count = 0; # count of instances created sub new { my $package = shift; my $self = SUPER::new(@_); # The class we inherit from counts its instances. # Since we're really creating one of us, adjust # its count downward, then point the object at # our counter. ${$self->{_count}}--; $_count++; $self->{_count} = \$_count; bless $self, $package; }