How can I expand variables in text strings? Let's assume that you have a string that contains placeholder variables. $text = 'this has a $foo in it and a $bar'; You can use a substitution with a double evaluation. The first /e turns $1 into $foo, and the second /e turns $foo into its value. You may want to wrap this in an "eval": if you try to get the value of an undeclared variable while running under "use strict", you get a fatal error. eval { $text =~ s/(\$\w+)/$1/eeg }; die if $@; It's probably better in the general case to treat those variables as entries in some special hash. For example: %user_defs = ( foo => 23, bar => 19, ); $text =~ s/\$(\w+)/$user_defs{$1}/g;