My understanding is that you should be able to put your DB cleanup code inside an END block in order to have it run before anything else is done about cleanup.
If you are already using END (not sure if that's what you mean by destructor or not), let me know and I'll see what else I can figure out.
An END block is simply:
END { ...code... }