in reply to comparing multiple files for patterns

Much as Athanasius suggested in Re: how to save patterns found in array to separate files, you can solve this issue using a hash. In particular, you want to use HASHES OF HASHES (as described in perldsc, see also perlref, perlreftut, perllol). Your first index is probably your filename, and your second is the line content:
use strict; use warnings; my %content; for my $animal ('dog', 'cat') { open my $fh, '<', "/tmp/$animal.txt" or die "Couldn't open $animal +: $!"; while ( my $line = <$fh> ) { ++$content{$animal}{$line}; } } for my $animal ('horse', 'lama', 'camel', 'tiger') { open my $fh, '<', "/tmp/$animal.txt" or die "Couldn't open $animal +: $!"; while ( my $line = <$fh> ) { for my $other ('cat', 'dog') { print "$other: $line" if $content{$other}{$line}; } } }

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.