in reply to subroutine reference parameters

It seems using the hash as an argument in the function call makes it reset the internal iterator used by each, thats why you get an infinite loop.

Also you are declaring your function with a prototype, but when you call it you use an &. The & disables the prototype check.