in reply to die and subroutine combo

Perhaps you could set $SIG{__DIE__}. Like this:
sub mysub { my $error = shift; print STDERR "mail stuff here..\n"; print STDERR "Error message: $error"; print STDERR "End of mail\n"; die $error; } local $SIG{__DIE__} = \&mysub; open(TMPFILE,"<datafile.txt") || die "Cant open: $!";