in reply to can't read the 2nd input file

The port-state-service+IP-mem.pl and port-state-service+IP-disk.pl program has been re-written and ignores SPACEs/TABs within IP and port files,that is a line ONLY containing SPACEs/TABs in the IP file is NOT inserted in the IP array it takes as input via command line arguement ARGV 0,1,2 the port file , the IP file and the output where numbered IPs from the port file are written along with the port,state and protocol.
The port file contains a number at the left that is intented to pick-up the Nth 0-based IP from the IP file,empty lines are ignored. I have made it on purpose to insert SPACEs/TABs and empty NEWLINEs just to show you that the program takes care of this and bellow the normal IP and port files WITHOUT SPACEs/TABs and empty NEWLINEs.
The port-state-service+IP-mem.pl was much easier to write and runs much faster than port-state-service+IP-disk.pl but may not work on computers with less memory. On the other hand port-state-service+IP-disk.pl runs with low constant memory but is much slower due to frequent disk access.
Again, thank you all for your help.

port file WITH SPACEs/TABs and empty NEWLINEs
3 80/tcp closed http 3 443/tcp closed https 3 8080/tcp open http-proxy 5 80/tcp open http 5 443/tcp filtered https 5 8080/tcp filtered http +-proxy 7 80/tcp open http 7 443/tcp filtered https 7 8080/tcp filtered http-proxy
IP file WITH SPACEs/TABs and empty NEWLINEs
1.0.129.197 1.0.131.49 1.0.131.74 1.0.138.143 1.0.138.154 1.0.139.72 1.0.129.191 1.0.129.192 1.0.129.193

IP file WITHOUT SPACEs/TABs and empty NEWLINEs
I have tested different forms of IPs (IP file)
1.0.XXX.XXX 1.0.0.X 10.00.00.XX 100.000.000.XXX 01.00.00.XX 001.000.000.XXX
1.0.XXX.XXX
1.0.129.197 1.0.131.49 1.0.131.74 1.0.138.143 1.0.138.154 1.0.139.72 1.0.129.191 1.0.129.192 1.0.129.193
1.0.0.X
1.0.0.0 1.0.0.1 1.0.0.2 1.0.0.3 1.0.0.4 1.0.0.5 1.0.0.6 1.0.0.7 1.0.0.8
10.00.00.XX
10.00.00.00 10.00.00.01 10.00.00.02 10.00.00.03 10.00.00.04 10.00.00.05 10.00.00.06 10.00.00.07 10.00.00.08
100.000.000.XXX
100.000.000.000 100.000.000.001 100.000.000.002 100.000.000.003 100.000.000.004 100.000.000.005 100.000.000.006 100.000.000.007 100.000.000.008
01.00.00.XX
01.00.00.00 01.00.00.01 01.00.00.02 01.00.00.03 01.00.00.04 01.00.00.05 01.00.00.06 01.00.00.07 01.00.00.08
001.000.000.XXX
001.000.000.000 001.000.000.001 001.000.000.002 001.000.000.003 001.000.000.004 001.000.000.005 001.000.000.006 001.000.000.007 001.000.000.008

and have the following output
1.0.XXX.XXX
IP port state protocol 1.0.131.74 80/tcp closed http 1.0.131.74 443/tcp closed https 1.0.131.74 8080/tcp open http-proxy 1.0.138.154 80/tcp open http 1.0.138.154 443/tcp filtered https 1.0.138.154 8080/tcp filtered http-proxy 1.0.129.191 80/tcp open http 1.0.129.191 443/tcp filtered https 1.0.129.191 8080/tcp filtered http-proxy
1.0.0.X
IP port state protocol 1.0.0.2 80/tcp closed http 1.0.0.2 443/tcp closed https 1.0.0.2 8080/tcp open http-proxy 1.0.0.4 80/tcp open http 1.0.0.4 443/tcp filtered https 1.0.0.4 8080/tcp filtered http-proxy 1.0.0.6 80/tcp open http 1.0.0.6 443/tcp filtered https 1.0.0.6 8080/tcp filtered http-proxy
10.00.00.XX
IP port state protocol 10.00.00.02 80/tcp closed http 10.00.00.02 443/tcp closed https 10.00.00.02 8080/tcp open http-proxy 10.00.00.04 80/tcp open http 10.00.00.04 443/tcp filtered https 10.00.00.04 8080/tcp filtered http-proxy 10.00.00.06 80/tcp open http 10.00.00.06 443/tcp filtered https 10.00.00.06 8080/tcp filtered http-proxy
100.000.000.XXX
IP port state protocol 100.000.000.002 80/tcp closed http 100.000.000.002 443/tcp closed https 100.000.000.002 8080/tcp open http-proxy 100.000.000.004 80/tcp open http 100.000.000.004 443/tcp filtered https 100.000.000.004 8080/tcp filtered http-proxy 100.000.000.006 80/tcp open http 100.000.000.006 443/tcp filtered https 100.000.000.006 8080/tcp filtered http-proxy
01.00.00.XX
IP port state protocol 01.00.00.02 80/tcp closed http 01.00.00.02 443/tcp closed https 01.00.00.02 8080/tcp open http-proxy 01.00.00.04 80/tcp open http 01.00.00.04 443/tcp filtered https 01.00.00.04 8080/tcp filtered http-proxy 01.00.00.06 80/tcp open http 01.00.00.06 443/tcp filtered https 01.00.00.06 8080/tcp filtered http-proxy
001.000.000.XXX
IP port state protocol 001.000.000.002 80/tcp closed http 001.000.000.002 443/tcp closed https 001.000.000.002 8080/tcp open http-proxy 001.000.000.004 80/tcp open http 001.000.000.004 443/tcp filtered https 001.000.000.004 8080/tcp filtered http-proxy 001.000.000.006 80/tcp open http 001.000.000.006 443/tcp filtered https 001.000.000.006 8080/tcp filtered http-proxy

port file WITHOUT SPACEs/TABs and empty NEWLINEs (there are 2 TABs between the line number and the rest of the line)
3 PORT state protocol 3 80/tcp closed http 3 443/tcp closed https 3 8080/tcp open http-proxy 5 80/tcp open http 5 443/tcp filtered https 5 8080/tcp filtered http-proxy 7 80/tcp open http 7 443/tcp filtered https 7 8080/tcp filtered http-proxy
I have tested different forms of Nth IPs with different number of leading '0's (IP port)
03 80/tcp closed http 003 443/tcp closed https 0003 8080/tcp open http-proxy 005 80/tcp open http 00005 443/tcp filtered https 0000005 8080/tcp filtered http-proxy 0007 80/tcp open http 0000007 443/tcp filtered https 000000007 8080/tcp filtered http-proxy

port-state-service+IP-mem.pl
die "perl port-state-service+IP-mem.pl <INPUT_FILE_ports> <INPUT_FILE_ +IP> <OUTPUT_FILE> " if $#ARGV < 2; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=0; while (<F1>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;chomp; $IP[$line_no++] = $& if /[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]\.[0- +2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]/; } close F1; print F2 "IP\t\tport\tstate\tprotocol\n\n"; while (<F0>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;s/\t+/\t/;chomp;/^[0-9]+/;$line=$';$line_no=$&; $line =~ s/^[\t\ ]+//g;$line =~ s/[\t\ ]+$//g ; print F2 $IP[$line_no - 1], "\t$line\n" if /[0-9]+\//; } close F0; close F2;
port-state-service+IP-disk.pl
die "perl port-state-service+IP-disk.pl <INPUT_FILE_ports> <INPUT_FILE +_IP> <OUTPUT_FILE> " if $#ARGV < 2; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$line_stop=0; print F2 "IP\t\tport\tstate\tprotocol\n\n"; while (<F0>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;s/\t+/\t/;chomp; if (/^[0-9]+/) { $line_port=$'; $line_no=$&; &get_IP; } } close F0; close F1; close F2; sub get_IP { while (($line_stop < $line_no) && ($line_IP = <F1>)) { $line_stop++ if $line_IP =~ /[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]\ +.[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]/; } if ($line_stop == $line_no) { $line_IP =~ s/^[\t\ ]+//g;$line_IP =~ s/[\t\ ]+$//g ;$line_IP +=~ s/\n$//g; $line_port =~ s/^[\t\ ]+//g;$line_port =~ s/[\t\ ]+$//g ; print F2 "$line_IP\t$line_port\n"; return; } }