use warnings;
use strict;

my @lengths = ('NM_1234' , '1452' , 'NM_345' , '5008' , 'NR_6145' , '256');
my @counts  = ('NM_1234' , '2',     'NM_345' , '5' ,    'NR_6145' , '10');

my %sequences = map { 
   $counts[2 * $_] => { count => $counts[2 * $_ + 1] } 
} 0..$#counts/2;

for (0..$#lengths/2) {
  my $the_sequence = $lengths[2 * $_];
  my $the_length   = $lengths[2 * $_ + 1];
  push @{ $sequences{$the_sequence}->{length} }, $the_length;
}

for my $name (keys %sequences) {
  my $lengths_string = join(', ', @{ $sequences{$name}->{length} });
  my $count = $sequences{$name}->{count};
  print "$name, $lengths_string, $count", "\n";
}
