@file1 = ; @file2 = ; foreach (@file1) { @record = split(',', $_); # so I can get name only $fullname = tr/()//d; # I don't want ( or ) in it $fullname = s/\s+/ /g; # Substitute one or more spaces anywhere with one space only (per space matched) # Now, I have $fullname with info I want to match against. foreach (file2) { @fileds = split(',', $_); # to get name only my ($lname, $fname) = split(/\s+/, $fields[5]); # so I can do a substring on the first name my $name = "$lname " . substr($fname, 0, 2); $name =~ tr/a-z/A-Z/; # You can tell me to use uc() function but for now I will use what I know if ($fullname =~ m/^$name/g) { # at this point if a string from my inner loop matches the one from the outter, print it out } } }