use English '-no_match_vars'; my %appearances_of; $appearances_of{$_}++ for map { split /\Q$SUBSCRIPT_SEPARATOR/ } keys %hash; #### $hash{$1,$3} = "$holder"; # add these lines: $appearances_of{$1}++; $appearances_of{$3}++;