in reply to Malformed Headers due to using scalar for address

I think you want "|mail $mail", not '|mail $mail'. The single quotes do not interpolate the data value, but the double quotes do.
@a=split??,'just lose the ego and get involved!';
for(split??,'afqtw{|~'){print $a[ord($_)-97]}