#!/usr/bin/perl use strict; use warnings; my $text; while() { $text=$text.$_; } my $repl={ foo_bar => { is => "foo", by => "bar" }, MS => { is => "rock", by => "suck" }, id => { is => "\{id\}(?[^\{]+)\{\/id\}", by => "ID: $+{id}" }, }; foreach my $p (keys $repl) { $text =~ s/$repl->{$p}->{'is'}/$repl->{$p}->{'by'}/g; } print $text, "\n"; __DATA__ My name is foo, yes foo. {id}1234{/id} Microsoft rocks!