recursive query with perl
===

I have the following table on db  which has 2 columns :

    from      to    
    00001     00002
    00001     00003
    00002     00003
    00002     00004
    00003     00001
    00003     00004
    00002     00004
    00004     00002
    00005     00003
    00005     00001
    00006     00007
    00009     00006

I need to get with perl and dbi  the  connection of speicific number  form example the output of 00001 will

will be the below connection :

00001 00002 0003 00004 00005
because 00001 connected to 00002 and 00003 and 00002 and 00003 connected to those new number  00004 and 00005 .

Is there an algorithm to implement this and what is the best soultion on perl to implement such algorithm ?

