http://www.perlmonks.org?node_id=535133


in reply to Matching string, then getting next line

Hi minixman

It would be worth trying a slightly different approach to the problem. You have mentioned that your content is coming from a file, it would be easier to work with the file itself line by line, look for the match and then do something with the next line. e.g.

while (<MYFILE>){ chomp; #remove line feed if (/do the match here/) { my $nextLine = <MYFILE>; # do stuff with the next line here. } }

This reads the content of the file handle, line by line placing each line into the default $_ variable. You can test to see if you have a match and then take another line from the file.

If you have all of your content in a list then you can substitute the reading of a line from the file with a shift of a line form the list.