use strict; use warnings; use Carp qw(cluck); sub new { return bless{}; } DESTROY { cluck 'cluck'; } sub foo { my $x = main->new; print "before\n"; undef $x; print "after\n"; } foo();