in reply to trapping database errors

Get rid of that local $SIG{__DIE__} stuff -- it serves no purpose here. Set RaiseError and then just do this:
my $mailbody; my $sth = $dbh->prepare($sqla); eval { $sth->execute(); }; if ($@) { $mailbody .= "Cannot insert into $database \n"; } else { $sth->finish(); # but why? probably not needed }