foreach $subdir(@subdirs) { chdir($subdir); @files=(); @files = glob "*.txt"; foreach $file(@files) { open(MYFILE, "<", $file); open($ohfivei, '>>905i.txt'); open($ohthreei, '>>903i.txt'); open($teni, '>>910i.txt'); open($ohfiveo, '>>905o.txt'); open($ohthreeo, '>>903o.txt'); open($teno, '>>910o.txt'); while ($line=) { #print "$_\n"; if($line=~(/$subdir/)) { ($undef, $mon, $day, $yr, $hr, $undef, $undef, $pr, $dir, $cc, $undef, $undef, $pegs, $undef) = split /,/, $line; $dt = ("$mon-$day-$yr $hr:00"); if ($pr=="905") { if($dir=="1") { print $ohfivei "$dt,$cc,$pegs\n"; } elsif($dir=="2") { print $ohfiveo "$dt,$cc,$pegs\n"; } } elsif ($pr=="903") { if($dir=="1") { print $ohthreei "$dt,$cc,$pegs\n"; } elsif($dir=="2") { print $ohthreeo "$dt,$cc,$pegs\n"; } } elsif ($pr=="910") { if($dir=="1") { print $teni "$dt,$cc,$pegs\n"; } elsif($dir=="2") { print $teno "$dt,$cc,$pegs\n"; } } } } close MYFILE; close $ohfivei; close $ohthreei; close $teni; close $ohfiveo; close $ohthreeo; close $teno; unlink "$file";