# private hash of instances my %instances; #... sub new { # ... build up $self, bless it, do whatever $instances{$self}=1; # ... whatever else you need to do... } #... sub DESTROY { # don't double-destroy return unless $instances{$self}; #... do whatever $instances{$self}=0; } END { foreach my $instance(keys %instances) { $instance->DESTROY() if $instances{$instance}; } }