How to use grep instead of the select and map methods