in reply to Tree in perl

It's a graph not a tree problem.

The IMHO easiest way to represent your data is a hash of arrays, (though the input format looks icky.)

For instance $edge{2}=[3,4]

So you'll need a parser to read the input into this HoA (see Perldsc for details) and a search algorithm like Dijkstra's algorithm.

Please show us some of your attempts to help you, I long stopped providing code for stuff looking like homework. ;)

Cheers Rolf

(addicted to the Perl Programming Language and ☆☆☆☆ :)

PS: tried to post this 5h ago but the site was unresponsive. in the meantime people tried to pamper the OP with ready to use code...O.o