That isn't as portable/reliable as Capture::Tiny, there are many such modules ... Capture::Tiny got created pretty late in the game but its the best of the best
Comment on Re^2: capturing stderr of echo piped to a file
Agreed. I was simply showing a way to do it that I found handy back before then in response to the stated desire to avoid extra modules. I'm not even sure it would work in the situation given, but might be worth looking at.
You must always remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.