my %line; { open my $fhA, '<', 'A' or die $!; while (<$fhA>) { $line{$.} = undef if /$X/; } }