use strict; use warnings; use Data::Dumper qw(Dumper); my $filea = FileA; my $fileb = FileB; open ( FA, '<', $filea) || die ( "File $filea Not Found!" ); open ( FB, '<', $fileb) || die ( "File $fileb Not Found!" ); my %ts; while ( ) { chomp; my($ids, $timestamp) = split ","; push @{ $ts{$timestamp} }, $ids; } while ( ) { chomp; my($life,$timestamp,$cls,$bool,$tot) = split ","; print STDERR "Loop tot-> $tot"; scalar ; for my $ids ( @{ $ts{$timestamp} } ) { last if $tot-- < 1; print join(",",$life, $ids, $cls )."\n"; } }