my @foo; my $next_a = ; scalar(); until (eof(DATA)) { my $a = $next_a; my @b; while (my $line = ) { last if $line =~ /^[*]{16}$/; push @b, $line; } my $found_next; my @c; while (my $line = ) { last if $found_next = ($line =~ /^-{16}$/); push @c, $line; } $next_a = pop(@c) if $found_next; push @foo, { a => $a, b => join("" => @b), c => join("" => @c), }; } use Data::Dumper; print Dumper \@foo; __END__ title 1 ---------------- a few random lines of more random text **************** some more random text title 2 ---------------- cow jumped over the moon **************** corn on the cob lobster thermidor