in reply to how to edit a file

Your question could use more details. I'll assume you're reading a list from a file, editing it, and writing it back to the same file.

open FILE, "myfile.txt" or die "Couldn't open for read!"; # stick all lines of file into an array of strings @lines = <FILE>; close FILE; open FILE, ">myfile.txt" or die "Couldn't open for write!"; foreach $line (@lines) { # create a list of words in each line @words = split ' ', $line; # editing code goes here if( $words[1] eq "posp" ) { $words[0] = "edited"; } # editing is done, now write the line to the file print FILE $_." " foreach( @words ); print FILE "\n"; } close FILE;