my %vehicles = ( Car=>{ Wheels=>4, Doors=>4, Color=>"Blue", }, Bike=>{ Wheels=>2, Color=>"Red", } ); # work with the attributes while (my($vehicle,$attributes)=each(%vehicles)){ print "Let me tell you about a $vehicle\n"; if(my $color = $attributes->{Color}){ print "A $vehicle is $color\n"; } if(my $wheels = $attributes->{Wheels}){ print "A $vehicle has $wheels wheels\n"; } }