if ($myobj->can('do_something')) { my $input = do_something_before(); my $result = $myobj->do_something($input); do_something_after($result); }