in reply to s/[newline]FOO[newline]/\\bar{foo}/sg

I have no idea how to use sed, and I'm surpised anyone would pass some other language through a source filter to convert it to Perl so that questions can be asked in Perl context. Imagine if we passed Perl through B::C to convert a script to C source code and then tried to ask questions about the spaghetti code in a C forum.

Here is a Perlish solution to what I think you're trying to accomplish:

my $string = 'stuff' # This should contain your original text. s/\n([a-zA-Z]+)\n/\n\\chapter{$1}\n/g;

This is untested, but should take you in the right direction for a Perl solution.

This fails if the chapter name is the first line of a file, since line one can't possibly have a newline preceeding it.

Update: Almost forgot the /g modifier.


Dave