This question is not Perl-specific, (although the unpack function will most probably figure into my implementation).
I have to deal with files where multipl
I would keep an additional state in one or more variables and update it per row. Then you e. g. know if the last line was level 1, or if the last row was format 4 (and you can expect format 5), thus giving more security to your processing.