in reply to Representing a connection matrix of graph

Here's another option:

use Modern::Perl; use Data::Dumper; my %rep; map {my @x = split; push @{ $rep{ $x[0] } }, $x[1]} grep /\S/, <DATA>; say Dumper \%rep; __DATA__ a b c d a d c a f g f h

Output:

$VAR1 = { 'c' => [ 'd', 'a' ], 'a' => [ 'b', 'd' ], 'f' => [ 'g', 'h' ] };

If there are no blank lines in your data set, you can omit the grep /\S/, in the script.

Hope this helps!