in reply to capture output and email on linux

What is the easiest way to capture output or mailing it or both?? For mailing you can use this:
open(SENDMAIL, "|/usr/sbin/sendmail -t") || die "Cannot open sendmail +: $!"; print SENDMAIL "From: some_email\@somewhere.com\n"; print SENDMAIL "To: some_email\@somewhere.com\n"; print SENDMAIL "Subject: $some_message\n"; print SENDMAIL "\n\n"; print SENDMAIL $some_content; close (SENDMAIL) or die "Cannot close sendmail: $!";
or
`echo "$msgbody"|mail -s "$subject!" user\@somewhere.com`;