How to sort a list with a given order?
my @orderby = qw( car boat chicken cat dog mouse );
my @list = qw( boat car mouse chicken );
my %orderby = map { $orderby[$_] => $_ } 0..$#orderby;
my @sorted = sort { $orderby{$a} <=> $orderby{$b} } @list;
Or if you want to mess with people's minds,
my @orderby = qw( car boat chicken cat dog mouse );
my @list = qw( boat car mouse chicken );
my %counts; ++$counts{$_} for @list;
my @sorted = map { ($_) x ($counts{$_}||0) } @orderby;