I like the idea of processing the data (file) line-by-line, but I would parse the data records to a structure, an array of arrays of lines in which each top-level array element is a "chunk." Once you have the data parsed into a structure, you can do what you want with it.
Win8 Strawberry 5.8.9.5 (32) Fri 04/02/2021 20:38:05 C:\@Work\Perl\monks >perl use strict; use warnings; use autodie; use Data::Dump qw(dd); my $test_data = <<'EOD'; GO:0002366 False GO:0002446 True GO:0002275 True GO:0043312 True GO:0006733 False GO:0019674 False GO:0043588 False GO:0055065 False GO:0055080 True EOD use constant { 'TRUE' => 'True', 'FALSE' => 'False', }; my $rx_tf = qr{ \Q${ \TRUE }\E | \Q${ \FALSE }\E }xms; print "\$rx_tf $rx_tf \n"; # for debug open my $fh, '<', \$test_data; my @chunks; my $i_chunk = -1; while (my $record = <$fh>) { chomp $record; my $got_tf_rec = # true if record is valid my ($tf) = # extracted true/false field $record =~ m{ \A GO: \d{7} \s+ ($rx_tf) \Z }xms; die "bad t/f record: '$record'" if not $got_tf_rec; die "first t/f record not false: '$record'" if @chunks == 0 && $tf ne FALSE; ++$i_chunk if $tf eq FALSE; push @{ $chunks[ $i_chunk ] }, $record; } dd \@chunks; close $fh; exit; ^Z $rx_tf (?msx-i: True | False ) [ [ "GO:0002366 False", "GO:0002446 True", "GO:0002275 True", "GO:0043312 True", ], ["GO:0006733 False"], ["GO:0019674 False"], ["GO:0043588 False"], ["GO:0055065 False", "GO:0055080 True"], ]
Give a man a fish: <%-{-{-{-<
In reply to Re: Parsing block of texts
by AnomalousMonk
in thread Parsing block of texts
by perlance
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |