in reply to redirecting STDERR, then back again
The documentation for open() perlfunc:open has an example of saving, redirecting, and restoring STDOUT and STDERR that you might find helpful.