my @args = map { ($_, foo($arg{$_})) } keys %args; # either: prepend \ to all $ in @args s/\$/\\\$/g foreach @args; # or maybe: quote all single quotes, then single-quote all args s/'/\\'/g foreach @args; @args = map "'$_'", @args; my @output = `/bin/foo @args`;