# create a regex that matches any one of the hash keys $regex = join("|", map(quotemeta, keys %hash)); # substitute them s/($regex)/$hash{$1}/eg;