$hash = {key1 => 'value', key2 => 'value'}; ... foreach my $key (keys %$hash) { s/%$key%/$hash->{$key}/eg; }