#!/usr/bin/perl -w use strict; my %hash = ( foo => 'bar', baz => 'quux' ); my $string = 'foo and baz'; while( my($k,$v) = each %hash ) { $string =~ s/$k/$v/g; } print $string;