sub mycmp ($$) { my ($first, $second) = @_; return 1 if $first ne ( mysort($first, $second) ); return -1 if $first eq ( mysort($second, $first) ); return 0; } # and elsewhere ... sort {&Whatever::Package::mycmp} map ... # or put in in a variable my $cmp = \&Whatever::Package::mycmp; ... sort $cmp map ... # of if you don't mind a speed hit and don't trust the user my $cmp = sub ($$) {Whatever::Package::mycmp(@_)}; ... sort $cmp map ...