<?xml version="1.0" encoding="windows-1252"?>
<node id="1003961" title="Re: How to grep exact string" created="2012-11-15 03:46:57" updated="2012-11-15 03:46:57">
<type id="11">
note</type>
<author id="27571">
ColonelPanic</author>
<data>
<field name="doctext">
This is a perfect case for the smart match operator.  You can do it like this:

&lt;code&gt;
foreach my $unique (@second_list_new)
{
    if ($unique ~~ @first_list_new))
    {
        print "already there $unique\n\n";
    }
    else
    {
        print "newly in this $unique\n\n";
    }
}
&lt;/code&gt;
This checks if any of @first_list_new is equal to $unique.  Unlike grep, it will stop as soon as it finds a match.
&lt;br /&gt;&lt;br /&gt;
If you do stick with the regex method, it would be a good idea to use \Q...\E around your variable:

&lt;code&gt;
    if (grep (/^\Q$unique\E$/,@first_list_new))
&lt;/code&gt;

This ensures that it will match the literal content of $unqiue.  Otherwise, some characters within $unique could be interpreted as special regex characters.  This wouldn't be a problem with the sample data you have shown, but if you were searching for a value like "foo.bar", for example, it wouldn't do what you want without \Q...\E, because the . would match any character rather than a literal dot.
&lt;br /&gt;&lt;br /&gt;
&lt;b&gt;Update:&lt;/b&gt; Of course, this doesn't answer why your original match failed.  Could it be a whitespace problem?  The second file that you posted above seems to have spaces at the end of the lines.  If this is the problem, you could either remove whitespace when you read the files in, or ignore it in your comparison.
&lt;br /&gt;&lt;br /&gt;
Here is an example of how you could remove trailing whitespace from one of the files, as well as do all of your other processing in one go. Note that you no longer need to chomp, because the m switch on the regex causes the newline to also be matched and removed:
&lt;code&gt;
     my @first_list_new = map { s/\s*$//m; lc $_ } &lt;FIRST_LIST&gt;;
&lt;/code&gt;


&lt;div class="pmsig"&gt;&lt;div class="pmsig-27571"&gt;
&lt;br&gt;&lt;br&gt;When's the last time you used duct tape on a duct?  --Larry Wall
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
1003945</field>
<field name="parent_node">
1003945</field>
</data>
</node>
