foreach my $log (@CommonLogFiles) { print "Now Processing $log....\n"; open LOG, "$datadir/$log" or die "LOG $log: $!\n"; print "Just opened $datadir/$log...\n"; $linecnt = 0; while () { chomp $_; $linecnt++; if ( $linecnt == "1" ) { $line .= "[$log] "; } $line .= $_; push @lines, "$line\n"; #print "Just added " . $line . " to the lines array...\n"; $line = ""; $linecnt = 0; } close LOG; } print APPLOG "Files parsed and data inserted into array for further processing...\n"; @sortedlines = sort { ($a =~ /^\<\d+\>\w+\s+\d+:\d+:\d+\s+\w+:TIMESTAMP\=(\w+\s+\w+\s+\d+\s+\d+:\d+:\d+\s+\d+).*MSGCLS.*$/m)[0] cmp ($b =~ /^\<\d+\>\w+\s+\d+:\d+:\d+\s+\w+:TIMESTAMP\=(\w+\s+\w+\s+\d+\s+\d+:\d+:\d+\s+\d+).*MSGCLS.*$/m)[0] } @lines; print SORTED "@sortedlines\n"; print APPLOG "Log files merged together with events in time order...\n"; close SORTED;