#!/usr/bin/perl use warnings; use strict; ; # Skip header. my %tree; while () { chomp; my ($child, $parent, $relation) = split /,\t/; $relation =~ s/,$//; $tree{$child}{parent} = [$parent, $relation]; } for my $node (keys %tree) { my @path = $node; my @relations = ($tree{$node}{parent}[1]); my $parent = $node; while ($parent = $tree{$parent}{parent}[0]) { push @path, $parent; push @relations, $tree{$parent}{parent}[1]; } print "$node:\t"; print join '<-', @path; print " = ", join '.', reverse grep defined, @relations; print "\n"; } __DATA__ child, Parent, relation M10, Q, P, M143, M10, P, M406, M143, PL, M407, M143, PL, M420, M143, E, M421, M143, E,