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 for 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 = <$PORT>)) { 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