my %objects; my $object; while (<>) { chomp; if ( my ($object_type, $object_id) = /^\s*object-group\s+(\S+)\s+(\S+)/ ) { $objects{$object_id} = $object = { type => $object_type, entries => [], }; } elsif (my ($entry) = /^\s*\S+-object\s+(.*)/) { push @{ $object->{entries} }, $entry; } }