in reply to Efficiency on Code

This is what I have, and when I run the code it is very slow. And it is only slow when the code inside the while loop runs if I commented out the while loop the code is very fast.

That seems to be a strong indication that fetching the data via DBI is not a problem at all (and neither is the SQL itself). Could it be that the cleaner subroutine is the slowest part?

What is cleaner doing? If this is a simple operation you could try to do it in SQL directly and select the clean value. That should speed things up.