use Scalar::Util qw[ dualvar ];; sub alwaysFails { return dualvar -123, 'Some text to explain the error'; } $rv = alwaysFails();; print "Sub failed with error: $rv" if $rv != 0;; Sub failed with error: Some text to explain the error