use strict; use warnings; my $filename = "file1.txt"; my $filename2 = "file2.txt"; my $logger = "log.txt"; my %seen; my @unique; my @strings; my %seen2; my @unique2; my @strings2; my $handle2; my $s; my $s2; my $seen; my $seen2; my $line2; open my $handle, '<', $filename || die "$0: Can't open $filename for reading: $!"; open my $FH, '>', $logger || die "$0: Can't open $logger for writing: $!"; while (my $line = <$handle>) { my @strings = $line =~ m/(RC[0-9][0-9][0-9][0-9])/; foreach my $s ( @strings ) { next if $seen{ $s }++; push @unique, $s; print $FH "@strings\n"; # push output to file log.txt for testing } } close $FH or die $!; #### use strict; use warnings; my $filename2 = "file2.txt"; my %seen2; my @unique2; my @strings2; my @line2; open my $handle2, '<', $filename2 || die "$0: Can't open $filename2 for reading: $!"; while (my $line2 = <$handle2>) { my @strings2 = $line2 =~ m/(RC=[0-9][0-9][0-9][0-9])/; foreach my $s2 (@strings2) { foreach my $s2 ( @strings2 ) { next if $seen2{ $s2 }++; push @unique2, $s2; print "$line2\n"; } } }