my $mailfh; if ( open($mailfh, '| /usr/sbin/sendmail -t -oi ') ) { print $mailfh 'From: test@example.org', "\n", 'To: admin@example.org', "\n", 'Subject: ERROR in blah blah', "\n", "\n", 'Error occured in ThisOrThat', "\n", "" . localtime(time), "\n", '.'; close($mailfh) or warn ("Mail not sent by sendmail: $!"); } else { warn ("pipe to sendmail cannot be opened: $!"); }