in reply to VVP:DBI, arrays and loops

Since...

Any advice would be welcomed!

... let me toss in my $.02. ;)

To start with, you should consider changing those 2 letter variables to something less obfuscated (aka more readable etc). At the moment, I have a very hard time understanding the very thing that your code is supposed to do and how it does it. If you need an array to store your purchase order numbers, then call it something like @purchase_orders. Apply same principle to the rest of your variables and this will make the code a little more readable.

"There is no system but GNU, and Linux is one of its kernels." -- Confession of Faith