in reply to need help editing lines of a file

If I understand you correctly, you want You have a number of options. The easiest to implement is to read the file into an array, then manipulate it. Something like this:
my @lines = <>; foreach my $index (0 .. $#lines) { if ($lines[$index] =~ /word/) { # Do what you want here, but to $lines[$index - 1] } }
The only problem with that method is if your text file is over 50% of your available RAM. Then, instead of being blazingly fast, it's only moderately fast.

Originally posted as a Categorized Answer.