my $LIMIT = 30; my $sth = $dbh->prepare("SELECT foo, bar FROM table WHERE baz=?"); $sth->execute( $baz ); my ( @rows, @row ); for ( 1 .. $LIMIT ) { last unless ( @row = $sth->fetchrow_array ); push @rows, [ @row ]; } #do stuff with @rows