You should always be using
use strict; use warnings;. The blizzard of while statements and substitutions is very confusing to me.
while (<F1> && ($line_stop++ < $line_no)) {
while (s/^[\ \t]//g) {} };
The reads a line from F1
and puts it into $_ which is thrown away, but if such a line was read (the read operation logically succeeded), then the statement compares $line_stop<$line_no. But $line_stop hasn't been declared yet, so this won't work. And we have the problem that the line itself is not available for processing. The second while loops until it cannot remove any more spaces or tabs at the beginning of the line. The while loops and the /g modifier is completely unnecessary.
s/^\s+//; would be sufficient, but none of your lines have extra white space at the beginning of the line, so that won't work either.
Your code is so confusing, I have no idea what it is really supposed to do. But I took a wild ass guess based upon just looking at the input files. Code below which uses a tricky feature of opening a Perl variable like an input file so that I can show everything as a single runnable Perl program.
Maybe back up and explain what you are trying to do?
use strict;
use warnings;
my $IP_file = << 'END';
1.0.129.197
1.0.131.49
1.0.131.74
1.0.138.143
1.0.138.154
1.0.139.72
END
my $Port_file = << 'END';
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
END
my $output_file;
open my $IP, "<", \$IP_file or die "unable to open IP file for
+reading $!";
open my $PORT, "<", \$Port_file or die "unable to open port file fo
+r reading $!";
open my $OUT, ">", \$output_file or die "unable to open output file
+for writing $!";
<$PORT>; # throw away first line ion port file
while (defined (my $ip_line =<$IP>) and defined (my $port_line = <$POR
+T>))
{
chomp $ip_line;
$port_line =~ s/^\d+\s+/$ip_line /;
print "$port_line";
}
__END__
Prints:
1.0.129.197 80/tcp closed http
1.0.131.49 443/tcp closed https
1.0.131.74 8080/tcp open http-proxy
1.0.138.143 80/tcp open http
1.0.138.154 443/tcp filtered https
1.0.139.72 8080/tcp filtered http-proxy