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