in reply to Use Mailx with Perl

Personally, instead of using mailx, I would use MIME::Lite to send the mail. If you really want to use mailx (maybe because your system administrator will support you better then), see system for how to run an external program, and/or open resp. perlipc for how to supply data to STDIN of a child process.