#!/usr/bin/perl use warnings; use strict; my @array = ('$HOME', '$USER'); print join("\n", @array), "\n"; map { s%\$([A-Z]+)%\$ENV{$1}%; } @array; print join("\n", @array), "\n";