grep iterates through all array elements, and in scalar context (as in this case), it returns the number of times an expression is true. Each expression in the greps is a regex that requires an exact match between the value of $host and an array element (contained in the default scalar, $_) to be evaluated as true.
Thank you for the comment. One more thing about this is the host string.
I see the host scalar to only work on the hostname if it only with db, but no other characters behind it, like db4323,
how would you include it to have any other characters like periods and numbers, behind it?
some example hostnames would be