Limit total users per level

Hello

Does anyone have any suggestions on code to limit the total number of allowed registered users for a sub-site, depending on its level?

Or even better, a way to limit the total number of users allowed on a sub-site of a certain role. For example, 2 administrators, 100 users etc...

Or a plugin if any exist already, that'd be great.

Cheers!