$ cat median.pl sub median { $_[0]->[ @{$_[0]} / 2 ] } my @sample=(9, 1, 2, 3, 4, 8, 7, 6, 5); my @sorted; @sorted=sort @sample; print median(\@sample),"\n"; print median(\@sorted),"\n"; $ perl median.pl 4 5 $ #### 5 5