The more elegant option is to use
IPC::Run3 instead of
system. It allows you to grab the STDERR of the program you run.
The quick and dirty way is to use a temporary file (it's fine if you need to use only core modules), however it will spawn a shell and probably will be much slower than
IPC::Run3.
The other "good" option using core modules only would be using
IPC::Open3, however this one is so tricky to use that it's close to unusable and extremely bug-prone, I wouldn't use it anymore because it's so difficult to get right...