in reply to Can someone tell me why this hangs??

This fragment compiles... BUT it makes no sense because you have many vars with no indication of how they're populated.

Neither do you give us any sample data which shows typical headers (post at least a representative fragment of data.txt, please) nor any hint of how you're determining where a header ends and its data begins... nor is there any indication of how you determine the value of $offset.

In short, my charitable assessment is that this is a badly-pared-down fragment of your code; my less charitable views aren't worth writing about.

But I am pretty sure you should read perldoc -f substr.

In any case, please, clarify.