use strict; package foo; our $counter = 0; sub new { my $class = shift; bless {id=>$counter++},$class; } sub DESTROY{ my $self = shift; print "DESTROYING $self->{id}\n"; } package main; test(); print "Back in main\n"; sub test{ print "Entering test\n"; if (1) { my $foo = foo->new(); } if (1) { my $foo = foo->new(); } if (1) { my $foo = foo->new(); } print "Leaving test\n"; } __OUTPUT__ Entering test Leaving test DESTROYING 0 DESTROYING 1 DESTROYING 2 Back in Main