1 - # think its a bad idea to start 2 - # with a false value here 3 - $n=0; 4 - 5 - open(OUT,">$n.out"); 6 - 7 - while(<>) { #where do you read from really? 8 - print OUT; 9 - 10- # that doesn't match anything, 11- # it will always return true 12- if (/foo/) { 13- # why do you do that? use a sub that returns 14- # a filehandle (or a reference to it) 15- close(OUT); 16- $n++; 17- open(OUT,">$n.out"); 18- } 19- } 20- close(OUT); 21