Checking which lines of a file are not in another file time efficiently in perl
<p>I want to compare a file to another file and find out what lines are found in the input file but not the file it is being compared to</p>

<p>This is my script right now</p>

<pre><code>#!/usr/bin/perl
my $data_file = "file.txt";
my @data;
{
    open my $fh, "&lt;", $data_file or die qq{Unable to open "$data_file" for input: $1};
while ( &lt;$fh&gt; ) {
    next unless /\S/;
    push @data, [ split ];
    }
}
my $found;
while ( &lt;&gt; ) {
    $found=0;
    my ($num, $spot, $sStart, $sStop, $name, $id, $start, $stop) = split;
    for $item ( @data ) {
        ($uNum, $uSpotStart, $uSpotStop, $uSpot, $udontUse, $uStart, $uStop, $uName) = @$item;
        if ( $uName eq $name and $start == $uStart and $stop == $uStop and $uNum eq $num ) {
            $found=1;
            last;
        }
    }
    if ($found==0){
        print $_;
    }
}
</code></pre>

<p>The script works but the problem is that it can never finish compiling because file.txt contains about 200,000 lines and the input file contains about 20,000 lines</p>

<p>This is an example of what would be in file.txt</p>

<pre><code>1   1729    1858    25  g   6600    6700    Sam
15  9302    9030    12  t   3900    4500    Frodo
19  0   2000    13  y   3300    3800    Merry
20  0   510 13  h   6300    6500    Pippin
</code></pre>

<p>While this would be the input file to the program</p>

<pre><code>1   25  1600    1700    Sam 40  6600    6700
15  11  1500    2000    Frodo   67  3900    4500
15  11  1500    2000    Frodo   67  3800    4500
17  10  3000    3100    Bilbo   50  2300    2600
19  20  3400    3700    Merry   39  3300    3800
20  90  3900    4200    Pippin  80  6300    6500
</code></pre>

<p>This should be the output</p>

<pre><code>15  11  1500    2000    Frodo   67  3800    4500
17  10  3000    3100    Bilbo   50  2300    2600
</code></pre>

<p>And it is but with the amount of lines I'm looking at I just can't do this time efficiently</p>

<p>I essentially want the script to do what it does now but with less processes involved when used on a larger scale</p>

<p>Thank-you!</p>