use strict; my ($type, $server,$out,$in,@input,$total,$kbytes,$mbytes); my @servers=('Server'); my $dir1='//machine/share'; my @types=('swf','asf','avi','mp2','mp3','mpg','mpga','mpe','mpeg','wav','mov','qt','mid','midi','ra','ram','rmi','rmj','rmx','zip','exe','wm','wma'); foreach $type (@types){ $total=0; my $out="$dir1/sifted/$type\.txt"; my $out2="$dir1/sifted/$type-ok\.txt"; open OUT, ">$out" or die "Cannot open $out for write :$!"; foreach $server (@servers){ $in="$dir1/$server\.txt"; open IN,"$in" or next; @input=; chomp @input; foreach (@input){ if (/\.$type$/i){ $kbytes = (stat)[7]/1024; $total+=$kbytes; print OUT "$_\t$kbytes KB\n"; } } close IN; } $mbytes=$total/1024; print OUT "\n\nTotal: $mbytes MB\n"; close OUT; if ($mbytes eq 0){ rename $out, $out2; } print "Finished $type...\n"; }