I have a perl script from within which I need to execute a simple perl one-liner on a remote host:
ssh 192.168.1.1 "perl -pi.bup -e 's/^(\s+?kernel)(.*)(?<!audit=1)$/$1$2 audit=1/' /etc/grub.conf"  This simply adds "audit=1" to the end of each kernel line in /etc/grub.conf if it does not already exist. 
The one-liner works just fine when run directly on the host, but not when executed via ssh from within another perl script. I have tried to escape all dollar signs with one or more backslashes and I have also tried to escape the backslash in "\s", but nothing I do seems to work.
Note I do not want to copy a script to the remote host and then execute it - I would like to do it using the ssh command directly.
How to properly escape this so that it works?
-- Update 9/9/2015 to show exactly what I am doing in the perl script:
sub SomeMethod { &RunCommand($host, "perl -pi.bup -e \'s/^(\s+?kernel)(.*)(?<!audit=1)\$/\$1\$2 audit=1/\' /etc/grub.conf"); } sub RunCommand { my ($server, $command) = @_; my $commandOutput = ""; if ($server ne "") { $command = "ssh $server \"$command\""; } $commandOutput = `$command`; print $commandOutput; if (($? >> 8) != 0) { &LogMessage ("$command failed:\n\n$commandOutput"); return $commandOutput; } return $commandOutput; }  -- Update #2, using system instead of back-ticks:
system 'ssh', $host, 'perl', '-pi.bup', '-e', 's/^(\s+?kernel)(.*)(?<!audit=1)$/$1$2 audit=1/', '/etc/grub.conf'; bash: -c: line 0: syntax error near unexpected token `(' bash: -c: line 0: `perl -pi.bup -e s/^(\s+?kernel)(.*)(?<!audit=1)$/$1$2 audit=1/ /etc/grub.conf'  Ok, I can use system here, but how to properly escape it??