use strict; my %trans = (color => 'red', fruit => 'apple', name => 'chromatic'); my $string = 'Hi, my name is $name. Please hand me a $color $fruit.'; $string =~ s/\$(\w+)/$trans{$1}/eg; print $string;