http://www.perlmonks.org?node_id=905319


in reply to Re: counting pairwise incidences
in thread counting pairwise incidences

Looks like ab ac ad to me, in which case it simplifies to:
use strict; use warnings; my %pairs; while (<DATA>) { my ($first, @names) = split; for my $second (@names) { my $p = join '_', $first, $second; ++$pairs{$p}; } } while (my ($k, $v) = each %pairs) { print "$k: $v\n"; } __DATA__ tomD gly4 phil aesG tomD gly4 phil aesG phil aesG tomD gly4