http://qs321.pair.com?node_id=1227532


in reply to Re: Override printing to STDOUT/ERR
in thread Override printing to STDOUT/ERR

While Capture::Tiny is simpler, the OP wanted to separate output according to the package/file the print() originates. So in this case, a tie-based solution like Tie::STDOUT is more appropriate as it lets you call your custom code on every print() or printf() or syswrite(), and then you can use caller() to extract the source location of each print() and act accordingly.