my %myHash = (hello=>"Howdy", goodbye=>"See ya"); while () { s/\$(\w+)/$myHash{$1}/eg; print; } __DATA__ When I want to say hello I say $hello. When I want to say goodbye I say $goodbye! #### s/\$(\w+)/dbLookup($1)/eg; sub dbLookup { # Do database lookup (which would take a few more lines!) return $lookedup ? $lookedup : ''; }