in reply to Simple but not elegant ?

I've been using Perl in EDI for about 14 years, and I think it's the ideal tool. Other than a dedicated translator.

Your example does not seem to match your code. If the beginning record header is H01..., \nH00 will not find it. Our applications produce similarly formatted files:

H0010|... H0020|... H0040|... D0010|1|.. D0020|... D0030|... D0010|2|... D0020|... D0020|... D0030|...

I tend to use a state machine and read thru the records sequentially, rather than try to separate the data into blocks using regexes. YMMV.

EDI files typically are delimited, so you should look into Text::CSV which, despite the name, can use most any delimiter and not just commas. It helps a great deal when your delimiter may occur within the data itself. It will reliably divide your records into fields. So will split, but the module handles special cases you may not think of until they occur and mess up your process.

If your fields are fixed length, substr() will work just fine. You may also want to look into unpack(), but it can be unforgiving if your data does not match expectations. Either will let you easily divide a record into named variables, and $ordernumber will be much easier to understand than substr($H01record,32,30) when you revisit the program 6 months from now.

Dum Spiro Spero