in reply to tag a matched text

indivauth's regex doesn't allow opposite ordering of given and surnames. Consider instead:

use strict; use warnings; undef $/; my $alt = '(?:sur|given)name'; my $content = <DATA>; $content =~ s#([^<]*)(<$alt>.*</$alt>)#$1."<authorfield>".&indivauth($ +2)."</authorfield>\n"#egi; sub indivauth { my ($inline) = @_; $inline =~s#(<$alt>(?:(?!$alt|</au>).)*?</$alt>)#<au>$1</au>#gsi; return "$inline"; } print $content; __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>

Prints:

<authorfield><au><surname>Coff</surname></au>, <au><givenname>D.,</giv +enname></au>, <au><surname>Coff</surname></au>, <au><givenname>D.,</g +ivenname></au></authorfield> <authorfield><au><givenname>D.,</givenname></au>, <au><surname>Coff</s +urname></au>, <au><givenname>D.,</givenname></au>, <au><surname>Coff< +/surname></au></authorfield>

DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.