my @split = map { s/^\[|\]$//m; $_ } split /\]\n[\S ]*\[|\n{2,}/, $text; my %match; for my $i (0 .. $#split) { my ($sec, $desc); ($match{PAGE}) = $split[$i] =~ /Pages? ([\d-]+)/ if (!defined($match{PAGE})); ($sec, $desc) = $split[$i] =~ m/^([A-Z]+):\s*(.*)/msg; $match{$sec} = $desc if ($sec and $desc); if (($match{ACTION} or $match{AGENCY}) and !$match{DESC}) { $match{DESC} = $split[$i - 1]; } }