use Data::Dumper; my $i1 =1; my %hash = (k1 => {k2 => ($i1 ? 'this' : 'that') }); print Dumper(\%hash) . "\n"; # this $i1 = 0; %hash = (k1 => {k2 => ($i1 ? 'this' : 'that') }); print Dumper(\%hash) . "\n"; # that