$found =~ s/ ENV{\" # match the characters: ENV{" (.*?) # followed by any characters -- this sequence is the "value", and the parentheses capture it into the special variable $1 \"} # followed by: "} / \$ENV( # and substitute a literal: $ENV(" $1 # followed by the captured "value" \") # followed by: ") /gx; # and repeat the search & replacement to the end of $found