in reply to Compare two files (Ip addresses)

I think it would make more sense to read File2 first, to get the labels that need to be associated with various IP ranges. If the known IP values are treated as hash keys (and company names are the hash values), then it becomes very simple to look up the addresses in File1, and spit out the company name when there's a match.

You just need to make sure to handle the IP-range issues properly -- if I understand the question, a File2 entry like "Company6-55.207.128.0-55.207.143.255" would be a hit for any File1 IP whose third component falls between 128 and 143. Something like this could get you started:

use strict; my %ip_company; open( I, "File1" ) or die "File1: $!"; while (<I>) { chomp; my ( $company, $bgn_IP, $end_IP ) = split /-/; next unless ( $bgn_IP =~ /^(\d+\.\d+\.)(\d+)\.\d+$/ ); my ( $bgn_q12, $bgn_q3 ) = ( $1, $2 ); next unless ( $end_IP =~ /^(\d+\.\d+\.)(\d+)\.\d+$/ ); my ( $end_q12, $end_q3 ) = ( $1, $2 ); # NB: if $bgn_q12 ne $end_q12, we need some different logic... $ip_company{$bgn_q12.$bgn_q3} = $company; if ( $bgn_q3 != $end_q3 ) { for my $next_q3 ( $bgn_q3+1 .. $end_q3 ) { $ip_company{$bgn_a12.$next_q3} = $company; } } } open( I, "File2" ) or die "File2: $!"; while (<I>) { chomp; ( my $lookup = $_ ) =~ s/\.\d+$//; if ( exists( $ip_company{$lookup} )) { print "$_ is part of $ip_company{$lookup}\n"; } else { print "$_ is not part of any known company\n"; } }
(not tested)

Handling a range like "123.45.67.89-123.89.45.67" is left as an exercise... (or maybe you do don't have to go there).

(update: fixed last sentence so it makes sense)