my $errormatching=0; my @errortext=''; while (<>) { if (not $errormatching) { $errormatching=1 if m{^\s*'Errors' =>}; } else { if (not m{^\s*\]}) { push @errortext, $_; } else { process_error(@errortext); @errortext=(); $errormatching=0; } } }