Capture::Tiny provides a simple, portable way to capture anything sent
to STDOUT or STDERR, regardless of whether it comes from Perl, from XS
code or from an external program. Optionally, output can be tee(1)'d so
that it is captured while being passed through to the original handles.
from Stephan A. Rickauer, with some tweaks by me