Count not correct

the count is off ... man ... help please.

The Code

open (FILE1, "xy1.TXT") or die "$0: Could not open SOURCEFILE.TXT: $!\n";
open (FILE2, "xy2.TXT") or die "$0: Could not open RESULTFILE.TXT: $!\n";

chomp(my @strings = <FILE2>);
while (1) {
 foreach $pattern (<FILE1>) {
  chomp($pattern);
 last if $pattern =~ /^\s*$/;
  my @matches = eval {
    grep /$pattern/, @strings;
  };
  if ($@) {
    print "Error: $@";
  } else {
    my $count = @matches;
    print "$count lines in the result file contain:  $pattern \n"
  }
}
exit;
}

///////////////////////////////////////////
the files

C:\perl>type cv1.txt
car
boat
house
girl
hate
C:\perl>type cv2.txt
boy
car
girl
dog
car
love
hate
boat
boat
hate
boat
boat
boy
girl
dog

///////////////////////////////////////////
The output

C:\perl>grepc.pl
0 lines in the result file contain:  car
4 lines in the result file contain:  boat
0 lines in the result file contain:  house
2 lines in the result file contain:  girl
2 lines in the result file contain:  hate

Nothing like answering your own question.

Spaces after the word car in file one.

Suppose a good idea to squash multiple spaces into one then chomp

maybe something like this?

$str =~ s/^\s+//;    # remove whitespaces from start of string
$str =~ s/\s+$//;    # remove whitespaces from end of string

I guess you are using different file names in the error messages as a platform for practical jokes? (^;