http://www.perlmonks.org?node_id=1210818


in reply to encode problems on AS400

In detail: seek to a point before the end of the file which you anticipate will be before the last-strings that you ... ahem ... seek. Now start reading, knowing that you probably landed right in the middle of a string (but not the string you want anyway). Read the remaining strings and, say, push them onto the end of an array. When you reach the end of the file, verify that the array contains at least three strings. An array-slice consisting of the last three strings is, in order, the data that you ... seek. (Do not stack the presumed-incomplete string that you probably landed smack-dab in the middle of ...)