$currpos = 0; while ( read( $dpf, $input, 80, $currpos ) ) { # get 80 characters from $currpos till EOF $input =~ m/($RID)(.*?)(?:$RID)/g; #grab a code, data and set pos # test $1 and $2 for errors $currpos = pos( $input ) # set pos in file to beginning of next id }