The docs say that when there are no more rows, fetchall_arrayref returns a reference to an empty array. That would imply your while loop would never terminate (a reference is always true, even if it's a reference to an empty array). gmax's suggested code above fixes that.
Comment on Re^3: DBI fetchall_arrayref using $max_size doesn't dereference normally.