I understand shell variables are local to the current shell while environment variables (the
$ perl -we "print qx'echo $FOO'"
It's because of shell variable interpolation in double-quoted strings.
$FOO variable is evaluated in the parent shell - in which
$FOO has value
bar - and interpolated into the quoted string.
Therefore the perl code you are actually running is:
print qx'echo bar'