http://www.perlmonks.org?node_id=1045374


in reply to System(), writing to a new file

Using the sort -o flag from Anonymous Monk's post...

You might want to consider this:
my $error_message = `sort -o $outfile $infile 2>&1`
The "2>&1" bit redirects errors on STDERR to STDOUT, and the latter will be saved in $error_message.