in reply to pop an array

foreach $item (@listoitems) { $item = pop(@listoitems);
What do you think this will do? You are iterating over an array, and while you are iterating, you not only modify the current element, you also modify the array. This is going to cause havoc. If you want to iterate over an array in reverse order, just use the reverse function.

Abigail