in reply to Pipe and return status through an "ssh"

You are kinda already testing the exit status of your command by using || echo FAIL in your shell command. How about just tacking on the exit status in the output:
my $cmd = q{ssh hosta -n "/tmp/test.sh; echo EXIT STATUS: $?"};
Then just look for EXIT STATUS: ... in your captured output.

Alternatively, look at Net::SSH::Perl. The cmd method will return the output, error output and exit status of a remotely executed command.