sub test{ my $i = shift; my $params = shift; my $test = $params->{test} if (exists $params->{test}); print "test after hash assignment:\t\t$test\n"; $test = $i unless (defined $test); print "i = $i test after defaulting to i:\t$test\n"; } for my $i (3..5){ &test($i) }