in reply to Need a little help appending lines

I'll try to use Tie::File

use Tie::File; #.......your code #at this point you have #@ports with port numbers #and file address.txt which you need to append tie @addresses, 'Tie::File', "address.txt" or die $!; for my $position (0..$#ports) { $addresses[$position] .= $ports[$position]; } untie @addresses;

But you may combine reading of the ports file and updating addresses file (with $. magick).