is it the right way to get the fastest fetch?
I don't know, you have run it and give some statistics on the time taken, memory consumption of the perl program, etc.
It would be great help if get an expert comment on the code
I am not a database expert, but IMHO using the database query's OFFSET AND LIMIT is the best way to fetch huge number of records, it is will take only minimum memory(depending on the offset and limit values), and effective values for limit will enable you to fetch all records in a optimum number of fetch cycles.
-- 'I' am not the body, 'I' am the 'soul', which has no beginning or no end, no attachment or no aversion, nothing to attain or lose.