my $cnt = 0; my @Values; my $dir = './FXE'; foreach my $fp (glob("$dir/*")) { #printf "%s\n", $fp; open my $fh, "<", $fp or die "can't open"; while (<$fh>) { # get rid of newline character chomp; # read the fields in the current record into an array @fields = split(/,/, $_); if($fields[0] >=1101227) { $Values[$cnt]= $fields[0]; $cnt++; $Values[$cnt]= $Values[$cnt] +$fields[1]; $cnt++; $Values[$cnt]= $Values[$cnt] +$fields[2]; $cnt++; $Values[$cnt]= $Values[$cnt] +$fields[3]; $cnt++; $Values[$cnt]= $fields[4]; $cnt++; $Values[$cnt]= $fields[5]; $cnt++; $Values[$cnt]= $fields[6]; $cnt++; $Values[$cnt]= $fields[7]; $cnt++; $Values[$cnt]= "\n"; $cnt++; } } close $fh or die "can't close"; $cnt=0; } print join(",", @Values), "\n";