in reply to Understanding Regex

First of all, you're processing a text file, so leave the MS Word stuff out of it. That's unnecessary and complicating things, as far as I can tell. I can see two ways to do this:

Process the file line-by-line, watching for lines starting with Function:. When you hit one, print it, then read in the next line (Input:) and save it, then read in the next line (Output:), stick a newline after the first colon, print it, then do the same with the Input: line you saved and print it, then print a new line. Start watching for a Function: line again.

The other way: read the whole thing into a single scalar variable, then write a regex to match the chunks of text that you're looking for, and loop through those chunks, printing out what you find in the format you want. Something like this (assumes a couple typos in your example):

while( $str =~ /(Function: .+?)\nInput: (.+?)\nOutput: (.+?)\n/gs ){ print <<END; $1 Output: $2 Input: $3 END }

In many languages you'd have no choice but to use the first method, which requires more programming logic. Perl's regexes are so powerful that you can replace a lot of logic with one big pattern match.

Aaron B.
Available for small or large Perl jobs; see my home node.