my @sorted_by_length = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, length($_) ] } @elements