sub DieWithCode { my $numerical_exit_code = shift; my $msg = shfit; # do something with $msg (inserting application name, linebreaks... if necessary if ($^S) { $EXITCODE = $numerical_exit_code; # module global var die ($msg); } print $msg; exit ($EXITCODE); }