use DBI; my $dbh = DBI->connect('dbi:mysql:test', 'test', 'test') or die; $dbh->do($_) for (split /\s*;\s*/, <<'END_OF_SQL'); drop table if exists foo; create table foo ( bar int ); insert into foo set bar=5; insert into foo set bar=4; insert into foo set bar=7; insert into foo set bar=1; insert into foo set bar=3 END_OF_SQL ##### my $sth = $dbh->prepare("select bar from foo") or die; $sth->execute or die; # $sth->fetchall_arrayref([0], 3) while (my $rows = $sth->fetchall_arrayref(undef, 3)) { for (@$rows) { print "got @$_\n"; } print "---\n"; } __OUTPUT__ got 5 got 4 got 7 --- got 1 got 3 --- #### __OUTPUT__ DBD::mysql::st fetchall_arrayref failed: fetch() without execute() at foo.pl line 23. --- DBD::mysql::st fetchall_arrayref failed: fetch() without execute() at foo.pl line 23. --- [... ad infinitum ..]