My guess is that mailx is working right on the perl script, but it nevers reaches that part of the code. Probably one of the ifs above make the
next command execute.
I just checked the ping command and the lines never have a "Redirect Host" string on them. Which would probably make the
next command execute.
Maybe you should see if those conditions are the ones you are going for. Perhaps your script is working right
Cheers!