use POSIX ":sys_wait_h"; my $mpid = open my $mh, "| /usr/sbin/sendmail" or die "$!"; print $mh << "EOF"; To: joe@here.com From: smith@here.com Subject: data subject message body here EOF close $mh or die "$!"; waitpid $mpid, 0;