#!/usr/bin/perl -lanF, # if the current key (in $F[0]) is not the same as the # last key we saw, print out the merged output line for # the last key and then start a new merged output # line for the current key if ($last_key ne $F[0]) { print $merged if $merged; $merged = $_; $last_key = $F[0]; } # otherwise, the current key is the same as the last, # and so we can merge this line's value portion (in # $F[1]) with the previous else { $merged .= ",$F[1]"; } # when we reach the end of the file, we must print # the final merged output line END { print $merged if $merged }