One cheap way is to simply always take the average of two elements, and let
the truncation of indicies handle finding the right elements, which will collapse
to adding the same element twice if the list is odd.
sub median {
my @sorted = sort { $a <=> $b } @_;
($sorted[$#sorted/2 + 0.1] + $sorted[$#sorted/2 + 0.6])/2;
}