annel has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, let's say if
text1: apple orange text2: apple apple
I try to delete the keys which are common in both text (only match once) and print out the mismatch. Apple of line 1 from text 1 and apple of line 1 from text 2 match, therefore deleted. But somehow apples of both lines in text 2 were deleted. Is there any better ways to delete just once for each existed data? After all of your generous help and tips,here is the code I have written. Cheers.
use strict; use warnings; open (FILE, "a") or die "Unable to open ref file.\n"; chomp (my @data1 =<FILE>) ; close(FILE); open (FILE, "b") or die "Unable to open new file.\n"; chomp (my @data2 =<FILE> ); close(FILE); my $size = @data1 < @data2 ? @data1 : @data2; my $result= @data1 < @data2 ? "File 1 has missing data" : "File 2 has +missing data"; my $ori = @data1 == @data2 ? 1:0; my $i; for( $i = 0; $i < $size; $i++){ if ($data1[$i] ne $data2[$i]){ printf "%s is mismatch with %s\n",$data1[$i],$data2[$i]; } else { printf "%s is match with %s \n",$data1[$i],$data2[$i]; } } print "$result\n" if (!$ori);
apple is match with apple File 2 has missing data
Another method I have tried by comparing the arrays one by one. But there is a tricky part. What if Text 1 has one line while Text 2 has two lines?