my $response = doSomething (); sub doSomething { #..do something which fails 0; } #### my $response = doSomething (); sub doSomething { eval { #..do something which fails }; if ($@) { # handle the error } 0; }