my $text="The respondent uses the following products XXX, YYYYYYYYY, ZZZZZZZ around the house and they are considering using QQQQQQQ too. They are particularly impressed with ZZZZZZZ."; my %replace=( "XXX" => "AAA", "YYYYYYYYY" => "BBBBBB", "ZZZZZZZ" => "CCCCCC", "QQQQQQQ" => "DDDDDDDD"); my $search=join '|',keys %replace; $text=~s/($search)/$replace{$1}/g; print $text;