thanks for the responses. Of course the adage "when in doubt read the manual" applies. My main problem was fetchrow_arrayref's use of the same reference for every row. Also the various ideas on dealing with the row count and optimizing the query are helpful.