This sounds like a matter of finding the connected components of a graph. Particularly if signal strength doesn't matter except as a boolean.
Something somewhat like this:
my @networks = ();
for my $device (@deviceList)
{
if (not defined $device->{network})
{
$_->{network} = $numDisjointNetworks for BFSonConnections($device)
+; #DFS works fine too
$numDisjointNetworks++;
}
push @{$networks[$device->{network}]}, $device;
}
should give you a LoL of networks and devices in them, and each device will know which network it is in.