in reply to Sorting text-number values

#!/usr/bin/perl # http://perlmonks.org/?node_id=1176809 use strict; use warnings; # sort by last number in each string print map $_->[0], sort {$a->[-1] <=> $b->[-1]} map [$_, /\d+/g], <DAT +A>; __DATA__ this_5_string_12 some_12_garbage_23 this_5_string_8 17 this_5_string_23 some_12_garbage_6 102 this_5_string_19 5 this_5_string_101

prints:

5 some_12_garbage_6 this_5_string_8 this_5_string_12 17 this_5_string_19 some_12_garbage_23 this_5_string_23 this_5_string_101 102