http://www.perlmonks.org?node_id=1025976


in reply to Reading from/writing to files with variables substitutions

Use a hash and a regex with the /e option.

#!perl -p use strict; use warnings; #Usage: perl script.pl boiler.txt >outfile.txt BEGIN{ use vars qw( %hash $pattern ); %hash = ( FIRST_NAME => 'James', COMPANY => 'SoftLayer', ); $pattern = join '|', keys %hash; } s/\$($pattern)/$hash{$1}/ge;
Bill