I thought about that approach but I rejected it. What exactly could you have the subroutine do? I think if you look at the source code, Net::SFTP will do nothing with the return value of the subroutine so your only option is to write it somewhere else. That is either going to be really bad and ugly or perhaps in some fascinating circumstances really elegant (but hard to understand).