in reply to Perl - make tool

Secondly I would like to know how exactly the sort routine works. Because I don't understand how the $a $b variables are passed to the anonymous subroutine. I would like to create $task variable within the anonymous subroutine I'm passing to the task method.
In retrospect, sort's use of $a and $b was a mistake. Note that code like sort foo 1..10; usually aliases $a and $b in the current package, but foo may be declared in some other package, and never see the sort-provided values. So sort was modified to pass the two values to compare as actual parameters, if and only if the subroutine specified has a $$ prototype.

For your case, just pass the task as a parameter to the anonymous sub.