sub resolve_envs { my ($path) = @_; while ($path =~ m/[^\\]\$\{?(\w+)\}?/) { my $env = $1; if (exists($ENV{$env})) { $path =~ s/([^\\])\$\{?(\w+)\}?/$1$ENV{$env}/; } else { $path =~ s/([^\\])\$\{?(\w+)\}?/$1\\\$$env/; } } $path =~ s/\\\$/\$/g; return $path; } #### set playground="${HOME}/playground" set file1=${playground}'/fi$le1' set file2=${playground}'/fi\$le2' mkdir -p ${playground} touch ${file1} touch ${file2}