#!/usr/bin/perl use warnings; use strict; my %data; while ( ) { my ( $key, $time ) = /([^\t]+\t[^\t]+)\t(.+)/ or next; if ( eof or not exists $data{ $key } ) { print join( "\t", %data ), "\n" if %data; %data = ( $key, $time ); } else { $data{ $key } = join ',', $data{ $key }, $time unless $data{ $key } =~ /$time/; } } __DATA__ 848 05/23/06 11:00 848 05/23/06 12:30 848 05/23/06 13:00 848 05/23/06 14:00 848 05/25/06 11:00 848 05/25/06 12:00 261 05/24/06 11:00 261 05/24/06 12:30 261 05/24/06 13:00 261 05/24/06 13:00 261 05/24/06 13:00 261 05/24/06 13:00