in reply to Changing foreach loop for a while loop

I rather suspect that the control structure change isn't going to help you. I'd be very curious to know how much time is being consumed by the elided lines ( . . . .) in your loop.

That said, here is one way -

while (@array) { my $info_element = shift @array; $sql= "SELECT C58XX.CCLMyy, C58XX.CLINyy FROM C58XX WHERE C58XX.CCLMyy=$info_element AND C58XX.CLINyy=$X_LINE "; .... }
(Premature Optimization is the root of all Evil ....)

----
I Go Back to Sleep, Now.

OGB