~$ raku -e 'my @a = slurp.comb( / "======" (<alpha>**3) "======" \v [ \V+ \v]+? <?before "======" | $ > /); \
.print for flat @a[0..1,(2..3).sort.reverse,4..*];' file
~$ raku -e 'my @a = slurp.comb( / "======" (<alpha>**3) "======" \v [ \V+ \v]+? <?before "======" | $ > /); \
.print for flat @a[0..1,(2..3).sort.reverse,4..*];' file
~$ raku -e 'my regex H { "======" <alpha>**3 "======" \v }; \
my @a = slurp.comb( / <H> [ \V+ \v ]+? <?before <H> | $ > /); \
.print for flat @a[0..1,(2..3).sort.reverse,4..*]' file
~$ raku -e 'my regex H { "======" <alpha>**3 "======" \v }; \
my @a = slurp.comb( / <H> [ \V+ \v ]+? <?before <H> | $ > /); \
.print for flat @a[0..1,(2..3).sort.reverse,4..*]' file
~$ raku -e 'my regex H { "======" <alpha>**3 "======" \v }; \
my @a = slurp.comb( / <H> [ \V+ \v]+? <?before <H> | $ > /).pairs; \
.raku.put for flat @a[0..1,(2..3).sort.reverse,4..*];' file
0 => "======abc======\ndata1\ndata2\ndata3\n"
1 => "======def======\ndata4\n"
3 => "======jkl======\ndata7\n"
2 => "======ghi======\ndata5\ndata6\n"
4 => "======mno======\ndata8\n"
#OR (another way of flattening):
~$ raku -e 'my regex H { "======" <alpha>**3 "======" \v }; \
my @a = slurp.comb( / <H> [ \V+ \v]+? <?before <H> | $ > /).pairs; \
.raku.put for @a[flat(0..1;(2..3).sort.reverse;[email protected])];' file
0 => "======abc======\ndata1\ndata2\ndata3\n"
1 => "======def======\ndata4\n"
3 => "======jkl======\ndata7\n"
2 => "======ghi======\ndata5\ndata6\n"
4 => "======mno======\ndata8\n"