my %res; foreach my $word (@rw) { $res{$word} ||= do { my $re; $re .= $translations{$_} for split //,$word; $re; } }