I would bet that you could make good use of btrott's Filehandle Filter to solve this problem in your code. You could filter STDERR do prefix all the lines with something like, "ERR: ", or better yet, do some work with caller() to get a stack trace on anything going to STDERR...
Comment on RE: How to split output using Expect.pm
Unfortunately not. btrott's filter only works on output
coming from your program (and even so has some limitations,
as I pointed out it won't catch output from xsubs or
system calls you make). kudra is interested in filtering
the output of another program.
However your basic idea is good, only the implementation
has problems. Indeed you could pipe STDOUT and
STDERR of the program through filters that would tag the
output. There probably is a nice way to do it, but one
silly and inefficient way is to launch a wrapper
program that opens pipes to two filter programs that will
tag their output, then launches your desired command using
IPC::Open3, connecting it's STDIN to yours, and its STDOUT
and STDERR to the two filters.
The wrapper can, incidentally, use the wait call to reap
the children and also get the exit code of the command you
are trying to wrap.