open(SENDMAIL, "|/usr/lib/sendmail -oi -t -odq") || die "Cannot for mail: $!"; # function? You'll want to specify real arguments, of course my $body=fuction(arguments); # Don't forget the Date: and Subject: headers print SENDMAIL << "EOF"; From: me\@abc.com To: you\@xyz.com $body EOF close(SENDMAIL);