sub slurp { local *ARGV; @ARGV = @_; <> } my %where; $where{$_} .= "1" for slurp($file1); $where{$_} .= "2" for slurp($file2); for (sort keys %where) { my $where = $where{$_}; if ($where =~ /12/) { print "both"; } elsif ($where =~ /1/) { print "left"; } else { print "right"; } print ":\t$_"; }