in reply to Parse File With Sub While Loops

More TMTOWTDI... Assuming your BH is predictable and has a static component...
FileStart
Batch: 123
234
1235613246
1434312
12521
124215
Batch: 133
614
1641
32463
142351
123
Batch: 358
214
125
612
FileEnd
Then you could set you Inpute Record Seperator to $/="Batch" and get each batch as a chunk, then process each chunk individually.
open IN, "somefile.txt"; $fileheadinfo = <IN>; $/ = "Batch"; while ($batch = <IN>) { next if $batch = "Batch"; #first line @lines = split /\n/,$batch; $batchinfo = "Batch" . shift @lines; #get batch info pop @lines; #get rid of bar Batch at end foreach $line (@lines) { process($line) } }