The most fundamental difference between my code and that posted in
Re: Splitting file into separate files based on record lengths and identifiers is the use of
^ in my regular expressions.
^ requires that the match start at the beginning of the string. Unlike some regular expression implementations (Java comes to mind), without that anchor Perl can begin a match anywhere in the string. The likely issue you are having with your posted code is that your order of operations is getting messed up because you may start in the middle of your string. My approach requires that you process the string in order.