plusplus is right ... the hashrefs array is probably the best choice of data structure. It is also more scalable; add more cars with push :
my @cars = ( { make => 'Toyota', Color => 'Red' }, { make => 'Ford' , Color => 'Blue' }, { make => 'Honda' , Color => 'Yellow' }, ); foreach my $car ( sort { $a->{make} cmp $b->{make} } @cars ) { foreach my $attribute ( keys %{ $car } ) { print $attribute, ' : ', $car->{$attribute}, "\n"; } }
source share