$resFolder = Somelocation; # defined in other part of the code @files = glob($resFolder ."/". "t-*.csv"); $numFiles = scalar(@files); $ResSummaryFile = $resFolder .'/' . 'ResSummary' . '.csv'; @header = ("filename","aa","ba","ab","bb","#_of_items","size_of_store"); my @tempReadOuts; ##loop through file list to extract necessary data (results): for ($i = 0; $i < $numFiles; $i++) { open(FH1, $files[$i]); print "Processing file... $files[$i]\n"; $tempReadOuts[0]=$files[$i]; open(FH2, ">$ResSummaryFile"); while () { chomp; @this_line = split("\n", $_); for ($j = 0; $j < scalar(@this_line); $j++) { ## code to extract syntaxes should go here; } print FH2 "@tempReadOuts/n"; } close(FH1); close(FH2);