my @data = qw( workstation_1_1 workstation_1_2 voiceserver_1_2 voiceserver_1_1 ); my @sorted = map { join('_', @{$_} ) # put the data back together again } sort { $a->[2] <=> $b->[2] # first sort by the final digit || $b->[0] cmp $a->[0] # then by the name, descending } map { # seperate the data out into seperate "fields" for easy # sorting (typically called a "Schwartzian Transform") [ split(/_/,$_) ] } @data; # the operation starts here (believe it or not)