while ($currpos < $filelen){ my ($readLen) = read $dpf, my ($recordID), 3; if (isValidID($recordID)) { #check the record length #if it is good, then parse the record for errors there #if the record is the wrong length, then skip parsing #when we read the next 3 chars we will probably not read a valid ID #and should begin hunting } elsif ($readLen == 3) { do { $dpf =~ m/\G.*MEH|MED|MMD|MMS|CR1|FR1/ig; } until (pos() >= $currpos); #this should put me at the record ID of the last #record I tried to parse #I will imagine there is a better way, particularly if #I can start from where the file pointer is and not from the beginning of the file if ($dpf =~ m/\G.*MEH|MED|MMD|MMS|CR1|FR1/ig) { #matching one more time will (hopefully) match the next record ID seek $dpf, pos(), 0; } #if it doesn't match, then this truncated record is the last record in the file (typical) else { seek $dpf, 0, 2; } } else { #if I didn't read three characters, then I hit EOF, seek there so $currpos will be updated and we will fall out of the while{} seek $dpf, 0, 2; } $currpos = tell $dpf; } #end while