my $empty = 1; while (my $row = $cursor->fetchrow_arrayref) { $empty = 0; print "$row->[0], $row->[1]\n"; } if ($empty) { print "EMPTY\n"; }