my %except = ( foot => -1, # sorts first hand => 1, # sorts last ); sub except_sort { return exists $except{$a} ? $except{$a} : exists $except{$b} ? -$except{$b} : $a cmp $b; } my @list = qw/leg hand eye foot jaw finger/; print join(" ", sort except_sort @list), $/;