in reply to Re^2: Combining multiple lines based on the given condition
in thread Combining multiple lines based on the given condition

One thing is certain as mentioned by other perlmonks before now that one need know how the OP input file is formatted.
Please see if the below codes gives some light.
Using the OP dataset just as was given and using perl split like thus:

use warnings; use strict; my $l = 'abc,2,3,4,5,6 abc,7,5,2,1,6,2,3 abc,8,2,1,3,1,4 ....... def,8 +,9,4,5,6 def,5,6,2,1 '; my %hash; my $k; for (split/[,. ]+/ => $l){ if(/\D+?/){ $k = $_ }else{ push @{$hash{$k}},$_ } } print $_,',',join (',' => @{$hash{$_}}),$/ for sort keys %hash;
Secondly, since your input is a CSV file, it is better you use module like Text::CSV or Text::CSV_XS.
See an example below with a modified OP dataset.
#!/usr/bin/perl use warnings; use strict; use Text::CSV; use Data::Dumper; my %hash; my $csv = Text::CSV->new( { binary => 1 } ) or die "can't use CSV" . Text::CSV->error_diag(); while ( my $row = $csv->getline(*DATA) ) { push @{ $hash{ shift @$row } }, @$row; # as previously mentioned + by Eily } $csv->eof or $csv->error_diag(); print Dumper \%hash; __DATA__ abc,2,3,4,5,6 abc,7,5,2,1,6,2,3 abc,8,2,1,3,1,4 def,8,9,4,5,6 def,5,6,2,1

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me