>perl -we 'use strict; 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,{});}' Use of uninitialized value $test1 in concatenation (.) or string at -e line 1. test1 after hash assignment: i = 0 test1 after defaulting to i: 0 test1 after hash assignment: 0 i = 1 test1 after defaulting to i: 0 test1 after hash assignment: 0 i = 2 test1 after defaulting to i: 0 test1 after hash assignment: 0 i = 3 test1 after defaulting to i: 0