Best way is to loop over $orders twice I think, with the flush between the 2 loops.