I think the strings coming back are literals so what I must
have is your case 1 which as you say doesn't work !
The literals contain strings that do map to local variables
so somehow I've got to translate the part that is the variable
to its value ?
(I tried splitting it up where the '$' starts but when I
set a new variable to:
$newcmd=$cmd1.$cmd2;
It seems to do the same thing.)
If you do have the unfortunate case of having the string not being interpolated then you could use the string version of eval() to get the desired result.
my $hr = { foo => { bar => '/dev/null' } };
my $cmd_literal = 'ls $hr->{foo}->{bar}';
my $cmd = eval qq(return "$cmd_literal";);
print `$cmd`;
__output__
/dev/null