#!/usr/bin/perl -w use strict; my %h = ( name=>"Mark", monk=>"extremely", typo=>"Weaknesses"); while () { s/<~([a-z][a-z0-9]*)~>/$h{$1}/g; print; } __DATA__ [<~monk~>|<~name~>] also wrote it like this: s/<~([a-z][a-z0-9]*)~>/exists $h{$1} ? $h{$1} : "<~$1~>"/eg; to expose <~typos-> and survive "-w" and "use strict". Try both lines!