my $regexp = 'some$thing'; my %values = ( 'thing' => 'THING', # ... other value mappings ); print $regexp; $regexp =~ s/\$(\w+)/$values{$1}/ge; print $regexp;