sub foo { #takes 2 arguments, a scalar(number between x and y) and a hashref my($scalar, $hashref) = @_; unless(($scalar =~ /^\d+$/) && ($scalar >= 7) && ($scalar <= 25) && ref($hashref) eq 'HASH')) { print "you're an idiot!\n"; return; } #gee, maybe i could be a little more informative here? #make the scalar jump through a hoop make_jump_through_hoop($scalar); #make a copy of the hash referenced by the hashref my %newhash = %{$hashref}; #set the hashref on fire set_on_fire($hashref); #multiply each value in the newly created hash by the foreach my $key (keys(%newhash)) { $newhash{$key} = $newhash{$key} * $scalar; } #return a reference to said newly created hash return \%newhash; }