while (<>) { if ($_ =~ /^(.*)\\ocwsection$/) { print "$1\n"; do { $foo = <>; } while ($foo =~ /^\\label/); print "\\section*{$foo}\n"; } else { print $_; } }