Here's my stab using a parser.
#!/usr/local/bin/perl use strict; use warnings; use HTML::TokeParser::Simple; my $data = do{local $/; <DATA>}; my $p = HTML::TokeParser::Simple->new(\$data); my ($in_tag, $in_g, @AoH, $tag, $txt); while (my $t = $p->get_token){ $in_tag++, next if $t->is_start_tag; $txt = $t->as_is if $t->is_text; if ($t->is_end_tag){ push @AoH, { tag => $t->get_tag, txt => $txt, }; $in_tag--; } } while (@AoH){ my @rec = splice @AoH, 0, 2; print '<au>'; printf "<%s>%s</%s>", $rec[0]->{tag}, $rec[0]->{txt}, $rec[0]->{tag} +; print ', '; printf "<%s>%s</%s>", $rec[1]->{tag}, $rec[1]->{txt}, $rec[1]->{tag} +; print '</au>,', "\n"; } __DATA__ <surname>Coff</surname>, <givenname>D.,</givenname>, <surname>Coff</su +rname>, <givenname>D.,</givenname> <givenname>D.,</givenname>, <surname>Coff</surname>, <givenname>D.,</g +ivenname>, <surname>Coff</surname>
outputs:
<au><surname>Coff</surname>, <givenname>D.,</givenname></au>, <au><surname>Coff</surname>, <givenname>D.,</givenname></au>, <au><givenname>D.,</givenname>, <surname>Coff</surname></au>, <au><givenname>D.,</givenname>, <surname>Coff</surname></au>,

In reply to Re: tag a matched text by wfsp
in thread tag a matched text by aakikce

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.