in reply to Re^3: perl -e in ssh
in thread perl -e in ssh

They're both the same problem.
$s = s/'/'\\''/g;
should be
$s =~ s/'/'\\''/g;

Fixed in original code. Tested.