Improved version of grep using perl