open IN, "somefile.txt"; $fileheadinfo = ; $/ = "Batch"; while ($batch = ) { 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) } }