my $BYTES = 0; $sftp->put( "testfile", "testfile", cleanup => 1, callback => sub { my ( $sftp, $data, $offset, $size ) = @_; print $offset ." of ". $size ." bytes copied\n"; last_bytes($offset); } ); print "\nTransferred $BYTES bytes\n"; sub last_bytes { my ($bytes) = @_; $BYTES = $bytes; }