in reply to scoping problem with Mail::Sendmail

From what I can tell from the docs of Mail::Sendmail, $Mail::Sendmail::log is only set after a send.

$Mail::Sendmail::log A summary that you could write to a log file after each send

However, you are using open (MAIL, "|/usr/sbin/sendmail -t") instead of sendmail(%mail) so $Mail::Sendmail::log is never set.

You might want to check out How do I send mail? and pick which method you actually want to use. If you do choose Mail::Sendmail, I would suggest reading the docs again.

l8rZ,
--
andrew