while () { chomp; ($a, $b) = split("="); if ($a ne $last) { print "$last=$words\n" if ($last ne ""); $words = $b; $last = $a; } else { $words .= ",$b"; } } print "$last=$words\n" if ($last ne "");