use strict; use warnings; my %res; while () { chomp; my ( $name, $date, @rest ) = split /\t/; push @{ $res{"$name\t$date"} }, @rest; } for my $key ( sort keys %res ) { my ( $name, $date ) = split /\t/, $key, 2; print "$name,$date:", join( "|", @{ $res{$key} } ), "\n"; } __DATA__ nick 20/5/1950 one john 18/2/1980 two two and a half nick 19/6/1978 three nick 20/5/1950 four nick 12/9/2000 five john 15/6/1997 six nick 20/5/1950 seven eight #### john,15/6/1997:six john,18/2/1980:two|two and a half nick,12/9/2000:five nick,19/6/1978:three nick,20/5/1950:one|four|seven|eight