Trying to avoid looping entirely might not be possible. I don't see anything in Win32::OLE that would help uniquely identify an object, and that would be required to avoid looping.
You could put limits on your looping (depth, time, number of objects visited, etc). Doing a breadth-first traversal (rather than a depth-first traversal) will make it easier to produce good results while adding limits.
sub depth_first {
my ($n) = @_;
for ($n->children()) {
depth_first($_);
}
}
sub breadth_first {
my @todo = @_;
while (@todo) {
my $n = shift(@todo);
push @todo, $n->children();
}
}