my $foo = `true`; my $err = $? >> 8; system("echo Error code is $err >> /tmp/foo"); #### #!/usr/bin/perl exit 0;