in reply to Looping through a binary file

while (<filehandle>) is implicitly while (defined ($_ = readline filehandle)) which reads a very long line. You probably wanted to check whether there is still data to read, which is done by the eof function.

Solution: use something like this: while (!eof(perlIN)).