ogd is a Perl module to ordered global destruction of objects stored in globals.
perl -m=ogd yourscript.pl # recommended
ogd->register( @object ); # for objects from XSUBs only
This module adds ordered destruction of objects stored in global variables in LIFO order during global destruction.
Ordered global destruction is only applicable to objects stored in non-lexical variables (even if they are in file scope). Apparently Perl destroys all objects stored file-level lexicals before the first END block is called.