package MyStuff; my $ending = 0; sub END { $ending = 1 } sub DESTROY { return if $ending; # more cleanup here }