$text = 'this has a $foo in it and a $bar'; $text =~ s/\$(\w+)/${$1}/g;
Before version 5 of perl, this had to be done with a double-eval substitution:
$text =~ s/\$(\w+)/$$1/eeg;
Which is bizarre enough that you'll actually need probably need an EEG afterwards. :-)