my $currentRegion = ''; my %regions = (); while () { chomp; /REGION (\d+) (.+)/ and do { $currentRegion = $1; $regions{$currentRegion}{Name} = $2; next; }; /REGION TOTAL (.+)/ and do { $regions{$currentRegion}{Total} = $1; $currentRegion = ''; next; }; do { push @{$regions{$currentRegion}{Data}}, $_ if $currentRegion ne ''; next; }; } #### # steve's regions (some added guessed region numbers for demonstration): foreach my $region ( @regions{ '7A', '8A', '9A' } ) { #do stuff to each $region that belongs to steve... }