use strict; use warnings; my %subs = (val => '123'); while () { s/\$(\w+)/$subs{$1}/g; print; } __DATA__ test_string_$val