use strict; my $file = "input.log"; my @sorted_ages; open (IN, $file) or die "Couldn't open file '$file': $!"; while (my $line = ) { chomp($line); my ($name, $age) = split(/,\s*/, $line); push @sorted_ages, $age; } close (IN); @sorted_ages = sort { $b <=> $a } @sorted_ages; #### use strict; my $file = "input.log"; my @sorted_ages; open (IN, $file) or die "Couldn't open file '$file': $!"; @sorted_ages = sort { $b <=> $a } map { # Use a regex to find the age # ^ = start of string, # .*?, = skips to the first comma # (\d+) = capture a number into $1 /^.*?, (\d+)/; $1 } ; close (IN);