my $phash = \%Tech_fy_reldata; # Assign to hash reference (eg. \%hash) while(){ @val=split /\t/; foreach my $val (@val) { my $pvalue = $phash; # Start with reference to hash if (CONDITION1) { $pvalue = $pvalue->{KEY1}; # Down 1 level if (CONDITION2) { $pvalue = $pvalue->{KEY2}; # Down another level # ... etc ... } } $$pvalue = VALUE; # Use $$ to dereference for assignment } } #### $$pvalue = VALUE; # Use $$ to dereference for assignment