sub SuggestionSort { my ($toSort, $Suggestion) = @_; my (%sugg, $i, @sorted); foreach (@{$Suggestion}) { $sugg{$_} = $i++ }; foreach (@{$toSort}) { if (defined $sugg{$_}) { $sorted[$sugg{$_}] = $_ } else { $sorted[$i++] = $_ } } grep defined, @sorted; } #### use strict; my @order = qw(whale elephant dog cat); my @sortme = qw(foo bar baz cat dog elephant bird); print join(", ", &SuggestionSort(\@sortme, \@order)),"\n";