# Passing <> <<$$>> executes <> $ ssh example.com echo '$$' 10920 # Passing <> <<'$$'>> executes <> $ ssh example.com echo ''\''$$'\''' $$ # Passing <> executes <> $ ssh example.com 'echo '\''$$'\''' $$ #### sub text_to_shell_lit(_) { return $_[0] if $_[0] =~ /^[a-zA-Z0-9_\-]+\z/; my $s = $_[0]; $s =~ s/'/'\\''/g; return "'$s'"; } my $remote_cmd = join ' ', map text_to_shell_lit, perl => ( '-e' => $perl_code ); backticks(ssh => ( '--', $target, $remote_cmd ));