use Table::ParentChild; use File::Slurp; my @relationships; my $i=0; foreach my $line (read_file("data")) { my ($child, $parent)= split ' ',$line; $relationships[$i++]= [$parent, $child]; } my $table = new Table::ParentChild( \@relationships ); my $child= 1045316419; while (my @parents = $table->parent_lookup( $child )) { print "Parent of $child is ", $parents[0],"\n"; $child= $parents[0]; }