in reply to Re^2: email subject issue in mailx
in thread email subject issue in mailx

-s => '$subject',

Don't know about your "undefined value as filehandle reference" error (Update: actually I do: you seem to have an ancient Perl (pre 5.6.1)), but you likely don't want single quotes around $subject.