in reply to Method references

This might be a good place to use a closure.   (Google it; see perldoc perlref.)   Basically, the caller passes a reference to a subroutine that is to be called, and when that call occurs, it will happen in the context that existed when it was made.   The routine that constructs the closure is thus able to know and to dictate not only what happens but also in what context it happens.   (It can refer to private variables, etc.)   The routine that executes it, now, does not have to know one closure from another.   All he has to do is to push that button; you determine what happens.

Conceptually, instead of passing a set of instructions that the other guy has to do (and, thus, making your correct-behavior dependent upon some distant piece of software “doing the right thing”), you instead hand him a tidy, self-contained box with a “Push Me” button on top.   All he has to do is to push that button.   You control everything that happens next.