raw 366:*: {
if ($nick($2, 0)) <= 5) /part $2
}

That will effectivly part you from a channel if there are less than (or equal to) 5 users


-KingTomato