sub func { my ($event, @planet_names) = @_; # read in parameters supplied by caller as in func($xyz) # check that we have some names and that event contains the fields we need # return undef on error. # caller must check if received undef! return undef unless @planet_names; return undef unless exists $event->{epoch}; ... my %returned_planets = (); for my $a_planet_name (@planet_names){ my $planet = Astro::Coords->new( planet => $name ); ... $returned_planets{$a_planet_name} = $planet; } # return to the caller results as a hashref # I always use refs for params and results. others may not. return \%returned_planets; } # end of my function # example use my $ret = func($anevent, "venus", "saturn"); die "func() failed" unless defined $ret; # and now do what you like with the results.