my $i = 1; my %hash = ( 'hk' => 5, 'jk' => 6 ); $hash{'abc'} = 7 if (! $i); foreach my $key (keys %hash) { print "the key is $key and val is $hash{$key}\n" }