in reply to Tk - intercepting alt-f4 and the like

You could also do this ...

sub END { print "Exitting\n"; #do clean up }

This should on any OS.
You might want to do a search on the subs BEGIN
and END.