Tie::Handle::Scalar and/or IO::Scalar should be able to do this with ease. Just tie the handle in question and print to it, getting the result in a scalar - or the other way around.
You have moved into a dark place.
It is pitch black. You are likely to be eaten by a grue.