open OLDFILE, $oldfilename or die "Can't open $oldfilename: $!\n"; # get length of first line my $start_pos = length(); # now read in next 11 lines for (1..11) { $_ = ; } # we've got the 12th line in $_ # nab the 6 chars starting at the 50th position of $_ my $field = substr($_, 49,6); #rewind to the beginning of the second line seek(OLDFILE, $start_pos,0); open NEWFILE, "> $oldfilename.new" or die "Can't open $oldfilename.new for write: $!\n"; print NEWFILE "STring with $field in it\n"; # now write eatch line of OLDFILE INTO NEWFILE print NEWFILE while (); close OLDFILE; close NEWFILE; rename ($oldfilename, "$oldfilename.bak") or die "Can't move $oldfilename: $!\n"; rename ("$oldfilname.new", $oldfilenme) or die "Can't create new $oldfilename: $!\n";