in reply to How to grep two strings from a File

I cannot do split as they are separated by space.

That is precisely why you would use split. eg:

#!/usr/bin/perl use strict; use warnings; while (<DATA>) { my @fields = split; print "Name = $fields[0], Dir = $fields[2]\n"; } __DATA__ FileName FilePath FileDir FileName2 FilePath2 FileDir2 FileName3 FilePath3 FileDir3