my $result = do_task(); exit() if ($result eq 'exit'); sub do_task { ... do something... if ($somecondition) { return 'exit'; } }