in reply to Re^2: File Intersection problem
in thread File Intersection problem

A few points about your updated code

Judging by the desired output in your OP, my understanding of your requirement is this

When you start processing lines in File2.txt you rather jump the gun by substituting the first name-associated data group by nothing before you know whether you actually need to keep it and also before you do anything with the preamble. The need to identify the preamble as well as extracting each data set leads me to slightly reconsider the compiled regular expression (see Regexp Quote Like Operators in perlop) I gave in my earlier reply. I would remove the second capture around the name to become

my $rxExtractNameData = qr {(?x) ( \s+ \w+ \s+ \([A-Z]\) \s+ \(\d*%\) \s+ \d+\s+\+\s+[+-]?\d+ ) };

which would allow me to use it both for the preamble and the data groups

... while( <$file2FH> ) { # reject line unless it has name data next unless m{^(.*?)$rxExtractNameData}; print $1; # preamble captured in $1 # global match to extract to an array my @dataGroups = m{$rxExtractNameData}g; ... } ...

Once you have the name-associated data groups you can loop over them pulling out each name, test whether it is in the hash parsed from File1.txt and, if so, print the data group.

I hope that I have correctly understood your requirements and that these thought will be useful.

Cheers,

JohnGG