It appears here you are opening
/usr/ucb/mail and not sendmail. Otherwise, this appears it would work. In the prior line, you would need :
# old
open(MAIL,"|$mailprog -t -f || die"" couldn't open mailprog $!")
# new
open(MAIL,"| $mailprog -t -f") || die "couldn't open mailprog $!";
hope that helps
update: this is , assuming,
$mailprog is
/usr/lib/sendmail
Thus spake the Master Programmer:
"When you have learned to snatch the error code from the trap frame, it will be time for you to leave."
--
The Tao of Programming