in reply to Line number in a file

Newlines aren't important when going through the data.
Yes, they are; they determine the line number you say you want :)

You are going to have to somehow keep track of them. Are the small parts of $_ you are working with handled consecutively? If so, you can just add up the newlines in each section as you finish working with it: $linenumber += y/\n//;