$hash{$1,$3} = "$holder"; # add these lines: $appearances_of{$1}++; $appearances_of{$3}++;