in reply to Preserving Calling Context

So, it seems like there is a lot of checks to wantarray here. An alternative would be to have a giant if (wantarray) dividing the sub into two implementations.

Or you could create a subroutine for each case and then create a wrapper subroutine to determine which one to call.