my $chunk = 0; my @data; open my $infd, '<', 'foo' or die "open: $!"; while (<$infd>) { next unless (my $c = /^-+/ .. /^\*+$/); next if ($c == 1); $chunk++, next if ($c =~ /E0$/); $data[$chunk] .= $_; } close $infd; ## show results for (0..$chunk-1) { print "-- beginning of chunk $_ --\n", $data[$_], "-- end of chunk $_ --\n"; }