# Get a hash of your translations, for quick lookup %pair_lookup = map { chomp; split(/=/, $_, 2); } ; foreach $name () { print NEWCUSTLIST // split the line into words and check if there // is a translation for it. If there is, return // the translation otherwise return the original join(" ", map { (defined $pair_lookup{$_}) ? $pair_lookup{$_} : $_; } split (/ /, $name, 2) ); }