use strict; my $err_string; close STDERR; open STDERR, '>', \$err_string or die "Could not redirect STDERR: $!"; print STDERR 'This is an error!'; print "***$err_string***\n";