sub text_to_shell_lit(_) { return $_[0] if $_[0] =~ /^[a-zA-Z0-9_\-]+\z/; my $s = $_[0]; $s =~ s/'/'\\''/g; return "'$s'"; } my $pat = quotemeta($hash2); my $repl = quotemeta($hash1); my $perl_code = 's/^'.$pat.'$/'.$repl.'/'; my $remote_cmd = join ' ', map text_to_shell_lit, '/usr/bin/perl' => ( '-i', '-p', '-e' => $perl_code, 'hashfile', ); my $ssh_cmd = join ' ', map text_to_shell_lit, 'ssh' => ( '-o' => 'StrictHostKeyChecking=no', 'root@localhost', '--', $remote_cmd, ); system($ssh_cmd);