$ perl -F, -lane '@F % 2 and push @D, [@F] or push @{$D[-1]}, pop @F; }{ $,=q{,}; print @{$_} for @D' input.txt #### 1/3/2007 12:20:01 AM,12.588309,9.432586,20:0.196329,7.418672,3.616305,2.066482,6.873061,0.784989,1.859894,3.249620,0.450952,0.305768,0.823402 1/3/2007 12:49:22 AM,10.958312,13.644527,41:0.483233,7.027840,4.222601,0.305821,7.443877,1.552915,1.202711,5.285398,0.233119,0.425521,0.560862 #### $ perl -MData::Dumper -F, -lane '@F % 2 and ($k)=@F or push @{$D{$k}}, @F; }{ $D{$_} = {@{$D{$_}}} for keys %D; print Dumper \%D' input.txt #### $VAR1 = { '1/3/2007 12:49:22 AM' => { 'ClientAdd' => '1.552915', 'CMALoad' => '1.202711', 'SearchDelete' => '0.305821', 'CMASave' => '5.285398', 'ClientDelete' => '0.425521', 'CMADelete' => '0.233119', 'Login' => '10.958312', 'SearchCount' => '41:0.483233', 'SearchDetails' => '7.443877', 'Logout' => '0.560862', 'SearchResults' => '7.027840', 'SearchSave' => '4.222601', 'SearchLoad' => '13.644527' }, '1/3/2007 12:20:01 AM' => { 'ClientAdd' => '0.784989', 'CMALoad' => '1.859894', 'SearchDelete' => '2.066482', 'CMASave' => '3.249620', 'ClientDelete' => '0.305768', 'CMADelete' => '0.450952', 'Login' => '12.588309', 'SearchCount' => '20:0.196329', 'SearchDetails' => '6.873061', 'Logout' => '0.823402', 'SearchResults' => '7.418672', 'SearchSave' => '3.616305', 'SearchLoad' => '9.432586' } };