The IO::Scalar module is one way to redirect STDERR to a scalar. There is another method for redirecting STDERR by using the IO::Capture module, and more specifically, by using the IO::Capture::Stderr module.
in reply to Best Way to Redirect STDERR to a Scalar
The CPAN site offers detailed description of this module.
my $capture = new IO::Capture::Stderr;
# ... print anything to STDERR ...
print STDERR "Test 1\n";
print STDERR "Test 2\n";
# To map everything into an array --
my @messages = $capture->read;