$a = "this is a test"; %b = ( is => 'was' ); foreach my $key ( keys %b ) { $a =~ s/$key/$b{$key}/g; } print $a,"\n"; # output: thwas was a test