#!/usr/bin/perl use strict; use warnings; if (@ARGV) { my $msg="This is printed to STDOUT\n"; { _die => sub () { local *STDERR=*STDOUT; die $msg; }, _print => sub () { print $msg; exit 0; } }->{+shift}->(); } sub chk { my $cmd=shift; my $ret=system $0 => $cmd; warn "Failure to run <$cmd>: $!\n" and return if $ret == -1; warn "<$cmd> died with status: ", $? >> 8, "\n" unless $ret == 0; } chk $_ for qw/_print _die/; __END__