Its guessing without seeing original code. Some thoughts:
- Do you use inside loop or in your calls 'next', 'redo' or other control statements?
- Do you add/remove some elements from @array inside loop?
It would be good to see those nested loops, we would definitely enjoy optimising them.