use List::MoreUtils qw(all); my ($first, @rest) = @things; my $ancestor = $first; while (defined $ancestor) { last if all { $_->has_ancestor($ancestor) } @rest; $ancestor = $ancestor->get_parent; }