Given only what you have told us so far, that task is impossible! We need a specification (not just an example) of your input 'file' format. Your original post implied that your file is an ASCII (not 'binary') file of fixed length records without separators. The only way to tell the end of a line was by its length. That is definitely a job for unpack. Note: I intentionally wrote the input in my example in a way that made every character (especially whitespace) explicit. If your lines are separated by an INPUT_RECORD_SEPARATOR (e.g. newline) unpack is probably overkill. Without a specification, we have to guess how to parse your file. That has not been going well for you.