my %People; while( my $id= GetNextId() ) { my( $name, $age, $addr, $city, $state, $phone )= GetDataForId( $id ); my $record= { NAME=>$name, AGE=>$age, ADDR=>$addr, CITY=>$city, STATE=>$state, PHONE=>$phone }; warn "Duplicate ID numbers: $People{ID}{$id} vs. $name\n" if $People{ID}{$id}; $People{ID}{$id}= $record; foreach my $field ( qw( NAME AGE STATE PHONE ) ) { push @{ $People{$field}{ $record->{$field} } }, $record; } } print "(The first) John Smith is ", "$People{NAME}{'John Smith'}[0]{AGE} years old.\n"; print "There are ",0+@{$People{AGE}{20}}, " 20-year-olds:\n"; foreach my $person ( @{ $People{AGE}{20} } ) { print "\t",$person->{NAME},"\n"; } #### print "(The first) John Smith is ", "$People{ByNAME}{'John Smith'}[0]{AGE} years old.\n"; #### my $byID= $People{ID}; foreach my $person ( @$byID ) { }