sub text_to_sh_literal { my ($s) = @_; s/'/'\\''/g; return "'$s'"; } my $arg_lit = text_to_sh_literal($arg); `some_command $arg_lit`