IMHO the best way is Capture::Tiny's capture_stdout, or capture if you want to grab STDERR as well.
In reply to Re: Divert STDOUT temporarily by haukex in thread Divert STDOUT temporarily by Xilman