sub check_errors { return unless ($ERRORCHECK == 1); my $st = system("ask-yes-no", "There were errors. Do you want to continue?") >> 8; if ($st != 0) { # exit the program } } #### ...do stuff... check_errors(); ...do more stuff... check_errors(); ... etc.