in reply to connected component

The Graph:: family of classes on CPAN should be able to help you. Using Graph::Undirected you can use the connected_components() method.