use strict; use warnings; my $sOut; close(STDERR); open(STDERR, ">", \$sOut) or die "Can't redirect STDERR to \\\$sOut"; print STDERR "Hello World!\n"; print $sOut;