#!usr/bin/perl.exe $a = 0; open(DUP, ">Duplicates found.csv") || die $!; open(NOR, ">Not in main.csv") || die $!; open(FILEM, "main.csv"); open(FILET, "tmp1.csv"); @file1 = ; @file2 = ; foreach $item(@file1){ $item =~ /(\d[0-9]{6,15}\d)/; $val = &bin_search( \@file2, $1 ); #Here are some example of the first line n @file2[1] #East Rd,GouisS Lees & PARTNERS, 12345678/1,JACOBS #and $1 is a example of 12345678 but it doesn`t match if(defined $val){ print DUP "$item"; } } close(FILEM); close(FILET); close(NOR); close(DUP); sub bin_search { my ($file2, $word) = @_; my ($low, $high) = ( 0, @$file2 - 1 ); while ( $low <= $high ) { # While the window is open my $try = int( ($low+$high) /2 ); # Try the middle element $low = $try+1, next if $array->[$try] lt $word; # Raise bottom $high = $try-1, next if $array->[$try] gt $word; # Lower top return $try; # We've found the word! } return; } }