my ($ret, $msg) = mysub( 'cat' => $val1, 'dog' => $val2 ); sub mysub { my $args = { 'cat' => undef, 'dog' => undef, @_ }; my $cat = $args->{'cat'}; my $dog = $args->{'dog'}; # do something with them if ($ok) { return($answer, undef); } else { return(undef, $error_msg); } }