my $limit = 3; my $curr = 0; my $type = ''; while (my @row = $sth->fetchrow_array()) {   if (++$curr > $limit && $type eq $row[0]) {    $curr = 0;    next;   }   $type = $row[0];   print @row,"\n"; }