in reply to safely passing args through ssh

Are there any other ways of solving this problem?

Yes, use Net::OpenSSH!

update (now that I have a real keyboard):

Net::OpenSSH does the quoting for you transparently. For instance...

$ssh->system('argcount', 'a;b;c');
says 1.

If arguments are passed as scalar references, an alternative quoting mechanism that lets glob patters pass unquoted is used:

$ssh->system('ls', \'/home/jsmith/*.png');

If you need to run your ssh commands through an intermediate machine, then you can...

$ssh->system('ssh', $host, $ssh->shell_quote($cmd, @args));
Though, probably, you would be able to bypass the intermediate host and get a Net::OpenSSH that runs commands directly on the remote side.