$connected{firstSet}{$n1}=1; # or better $connected{1}{x}=1; $connected{secondSet}{$n1}=1; # or better $connected{2}{x}=1;