@sorted=sort by_list(\@sortorder) @tobesorted; .... sub by_list{ @sortorder=@{$_[0]}; .....