#!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;