use IO::Capture::Stderr; my $capture = new IO::Capture::Stderr; $capture->start(); # ... print anything to STDERR ... print STDERR "Test 1\n"; print STDERR "Test 2\n"; $capture->stop(); # To map everything into an array -- my @messages = $capture->read;