if(exists($final->{$x[$i]})){ print "second\n"; ($final->{$x[$i]}, $f); } else{ print "first\n"; $final->{$x[$i]} = ($final->{$x[$i]}, $f); }