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 ; foreach ( 1 .. $tot ) { my $id = shift @{ $ts{$timestamp} }; print join(",",$life, $id, $cls )."\n"; } }