nick 20/5/1950 one john 18/2/1980 two 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 #### nick 20/5/1950 one four seven john 18/2/1980 two nick 19/6/1978 three nick 12/9/2000 five john 15/6/1997 six #### use strict; use warnings; my %res; while (<>) { my ( $name, $rest ) = split /\t/; push @{ $res{$name} }, $rest; } for ( sort keys %res ) { print "$_ ", join( "|", @{ $res{$_} } ), "\n"; }