Test::Trap


Trap exit codes, exceptions, output.

Or use Capture::Tiny and then interrogated the returned values.