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