my $account_data = $ssh->add_account( login => q{bob}, uid => 123 ); if ($ssh->success){ print qq{success: user added\n}; # do something with $account_data } else{ printf qq{failed: %s\n}, $ssh->error_msg; # try next user } sub add_account{ my $account_data; # ... $ssh->{success} = 0; if (condition){ $ssh->{success} = 1; } elsif (condition){ $ssh->{error_msg} = qq{uid not unique}; } else { $ssh->{error_msg} = qq{unknown error}; } return $account_data; } sub success {shift->{success} }; sub error_msg {shift->{error_msg} };