open (INFILE,"outfile.txt); while () { # $_ will hold one line of your file, and the loop will (slowly) go through your entire file #Mangle $_ here e.g. s/^\+host-1-3-1-10:/$ipnum/; #print it into the other file print OUTFILE $_; }