Regex could be work aswel but don't you think the performance of 'in_array' is better than using a regex?
sub.sub.sub.sub.mydomain.tld is possible, I use the 'array_reverse' function for that.