my @sorted = sort { sorter($a, $b, $offset) } @list; # ... sub sorter { my ($left, $right, $offset) = @_; ... }