Your 'while' reads in a line of the file, which, being a binary file, is not what you want to do. You can redefine what a 'line' is by setting $/
). If you set it to a reference to an integer (e.g. $/ = \42;
), it will read that many bytes. You can set it to the length of your fixed length record. But then you will have to adjust how you set your variables in the following lines (by using substr
or something) to 'read' from $_
instead of reading from the filehandle again.