in reply to Count number of lines in a STRING

You can use the same techniques for counting the number of lines in a string as you do for counting in a file; you just omit the part where you open the file, read the string(s) from the file, and close the file.

Just operate on the string directly.

(At least the technique described in perlfaq5 can be easily used that way).