my %variables = ( ... ); ...; while () { s/\$(\w+)/$variables{$1}/eg; print; }