my $name = $tree->ancestor->son->sibbling; if ($name =~ /john|jacob|jingle|heimer|smitz/) { # ... }