in reply to passing a command line argument

The problem is that in case if $string contains characters like $ or @ or % then these values are getting replaced by the perl keys.
No it doesn't.

"Interpolation", as it's called, goes only one level deep. Hence, it's the string contents of the variable $string that is inserted in the command line. Contrary to what you seem to believe, nothing else is replaced.

And %hash is never interpolated in a string. Never.

What may happen is that the invoked shell may treat shell metacharacters in this command line special (for example, replace parts of the command line by environment variables). But that's not Perl's fault. That's why $d may appear to disappear from your command line.

Use of String::ShellQuote may help you in alleviating that problem.

Replies are listed 'Best First'.
Re^2: passing a command line argument
by Fletch (Bishop) on Oct 04, 2007 at 12:01 UTC

    Alternately use the LIST form of system yourself directly (or IPC::Run if you need the output from the subprocess) and take any intermediary shell out of the picture to begin with and you won't need to worry about quoting.

    my $test_sh_ret = system( "test.sh", $string );