Implementing grep function.