This has been covered a few times. Check out:
The bottom line? Perl implements arrays by creating a block of memory, and then pointing the beginning of the array as an
offset into that block. When you try to
unshift too much onto the beginning of the array such that we run out of room at that end of the chunk of memory, perl goes to allocate more memory, and, again, keeps a chunk free at the beginning. However, if you're shifting off the array until it's empty, perl just keeps incrementing the "beginning" pointer until the beginning and end point at the same place, meaning a length of zero. There is no copying here whatsoever.