in reply to I don't understand this grep

I am not familiar with what grep does
As the documentation says, grep filters a list according to a specified condition, and returns a new list, when called in a list context, as your code does.

Since your sub does not have an explicit return, the sub returns what grep returns, namely a list.