in reply to die function and notifications

I was going to suggest $SIG{__DIE__}, but broquaint got there first. So instead I'll suggest that you wrap your entire progream in an eval block:
eval { ... }; if ($@ ne "") { my $error = $@; cleanup(); die "error was: $error\n"; }
See also: http://www.c2.com/cgi/wiki?ExceptionHandlingInPerl. --Dave