print 'THREAD ID,LOG DETAILS'."\n"; foreach my $filename (glob("$dir/*.out")) { open(my $fh, "<", $filename) or die "Could not open '$filename'\n"; while ($line = <$fh>) { my $i=2; chomp($line); if($line=~ $startmsg[$i]) { chomp ($line); my $threadid=$line; $threadid =~ s!(\d*)\s*.*!$1!; my $startdetails=$line; $startdetails =~ s!(\d*)\s*(.*)!$2!; chomp($threadid); print "$threadid,$startdetails \n"; my $flag = 'False'; OUTER: while ($line = <$fh>) { if ($line=~ m/$threadid/) if($line=~ $endmsg[$i]) { chomp ($line); my $enddetails=$line; $enddetails =~ s!(\d*)\s*(.*)!$2!; print "$threadid,$enddetails\n"; $flag='True'; last OUTER; } } } } } close($fh); }