in reply to How to sort?

Here is yet another way to accomplish the task. Hopefully I understood your question and this gets you your expected results.

update: this just accomplishes the sorting
use strict; use warnings; print map { $_->[0] . "\n"; } sort { $a->[1] cmp $b->[1] } map { chomp +; [$_, /\d+\s+([a-zA-Z]+)/]; } <DATA>; __DATA__ 1 Charlie 1 Edward 2 Bob 2 Alfred 3 Barry