use strict; use warnings; my @ages; while () { chomp; push @ages, (split /[, ]+/)[1]; } print join "\n", sort {$b <=> $a} @ages; __DATA__ Charley, 34 Sam, 3 Lucy, 18 #### use strict; use warnings; my @ages; while () { chomp; push @ages, [split /[, ]+/]; } for (sort {@$b[1] <=> @$a[1]} @ages) { print join (', ', @$_) . "\n"; } __DATA__ Charley, 34 Sam, 3 Lucy, 18