#!/usr/bin/perl use strict; use warnings; $>++; # get 500 random ip adresses, see genip code below my %need; open IP, "./genip |" or die "ooeps $!\n"; for (1..500) { my ($a, $b, $c, $d)=split /\./, ; $need{$a}{$b}{$c}{$d}++; } for (1..10_000_000) { my $ip=; my ($a, $b, $c, $d)=split /\./, $ip; # the compiler may optimise this line ... # next unless exists $need{$a}{$b}{$c}{$d}; # so all the following can probably be replaced # but it is too late for me to benchmark, g'night next unless exists $need{$a}; next unless exists $need{$a}{$b}; next unless exists $need{$a}{$b}{$c}; print "a.b.c\n"; # see how sparse we are ! next unless exists $need{$a}{$b}{$c}{$d}; print "match ! $ip\n"; } close IP; __END__ # Random IP address generator used above ... #!/usr/bin/perl use strict; use warnings; while (1) { my $ip = int rand 256; for (1..3) { $ip.= "." . int rand 256; } print $ip, $/; }