my %data; my $latest = ''; while() { chomp; if(/^([A-Z]+)\s*/) { #a line with all caps... new section $latest = $1; #what section are we in next; #go to next line } if($latest) { ## Next line handles $data{$latest} as an anonymous ## array, allowing you to store all the lines for ## each section that way push @{$data{$latest}}, $_; #just puts the line in, you could process it somehow } }