in reply to How to replace envs in path?

To take care of undefined environment variables you can code something like

$path =~ s<\$(\w+}/>< $ENV{$1} // $1 >ge;

if you are under at least Perl 5.10. The /e qualifier causes the replacement to be interpreted as an expression, not a string. Note that I had to change the delimiters to something other than C<'/'> to accommodate the defined-or operator.