in reply to infinite loop on while (@array)
Yes, but that code fragment won't do what you expect.
There are lots of ways to do things in Perl. Please say more about what, exactly, you're trying to do.