my $max = 700; my %seen = (); my $run = 1; while($run) { my $lncount = 0;   while() {        my $r = int(rand(2));      if($r == 0 and not exists $seen{$lncount}) {         print OUT $_;         $seen{$lncount} = 1;         --$max;         if($max == 0) {             $run = 0;             last;         }              }      ++$lncount;   }   seek(IN, 0, 0) if $run; }