http://qs1969.pair.com?node_id=11137777


in reply to Re: Assigning printf to a variable
in thread Assigning printf to a variable

local( *STDOUT ) = $fh;

Or select, though in this example local does have the advantage that it is restored after the block ends.

But in general, when wanting to capture STDOUT/ERR, I'd recommend Capture::Tiny.