use warnings; use strict; { package Tracer; sub new { my $c=shift; bless {@_}, $c } sub DESTROY { print "DESTROY ".shift->{name}."\n" } } END { print "END\n" } my $one = Tracer->new(name=>'one'); my $two = Tracer->new(name=>'two'); sub foo { my $three = Tracer->new(name=>'three'); my $four = Tracer->new(name=>'four'); $one->{foo}++; print "end of sub foo\n"; return $three; } my $th = foo(); print "clearing \$th\n"; $th = undef; print "end of main\n"; __END__ end of sub foo DESTROY four clearing $th DESTROY three end of main DESTROY two END DESTROY one