# assume line is: # ip;ip;ip;.. datum # my %ip_hash; while ( my $line = ) { my ( $ip, $datum ) = split /\s*/, $line; my @ip = split /\;/, $ip; foreach my $ipa ( @ip ) { $ip_hash{ $ipa } = $datum; } } # Later.. if ( exists $ip_hash{ $query_ip } ) { do_something_with_datum( $ip_hash{ $query_ip } ); } else { do_not_found_action( $query_ip ); }