use strict; use warnings; my @dataA = ( ['this', 0], ['array', 2], ['is', 3], ['an', 1], ); my @dataH = ( {word => 'this', index => 0}, {word => 'array', index => 2}, {word => 'is', index => 3}, {word => 'an', index => 1}, ); print "$_->[0] " for sort {$a->[1] <=> $b->[1]} @dataA; print "\n"; print "$_->{word} " for sort {$a->{index} <=> $b->{index}} @dataH;