use warnings; use strict; my $onlyUse = 0; my @unitRow; my $csr2 = bless {count => 0}; my %seen; while (my @unitRow = $csr2->fetchrow) { my $unit = $unitRow[1]; unless ($seen{$unit}) { $seen{$unit}++; $onlyUse++; print " $onlyUse "; next; } } sub fetchrow { my $self = shift; return () if $self->{count} > 20; return (0, ++$self->{count}); } #### 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21