Yes, you could use an XML parser to do the job described below but this case is pretty simple. Here's my offering leaving out the reading/writing of the files.
------------------ my $s = <<"EOF"; <index-item> <index-entry>APOE e4 variant</index-entry> <pageId>18</pageId> </index-item> <index-item> <index-entry>arousal disorders</index-entry> <see href="c-86679-1" label="see">disorders of arousal</see> </index-item> <index-item> <index-entry>arterial blood gas tests</index-entry> <pageId>32</pageId> </index-item> <index-item> <index-entry>asthma</index-entry> <pageId>28--9, 295</pageId> </index-item> EOF $s =~ s{<index-entry>(.*?)</index-entry>\s*<pageId>(.*?)</pageId>} {<index-entry pages="$2">$1</index-entry>}g; print $s; ------------------ You could replace the two .*? with [^>]* if you wanted to be more precise but it looks more confusing. Jon ========== original query ============ Hi All What will be the perfect Regular Expression to convert below mentioned 'Search Text' to 'Replacement Text' while 'Single Line' option is ON. When I use below mentioned Regex <index-entry(?:[^>]+)?>((?!<\/index-entry>).*?)</index-entry> \s*<pageId>([0-9]+)</pageId> And replaces wrongly <index-entry pages="32">arousal disorders</index-entry><see href="c-86679-1" label="see">disorders of arousal</see> </index-item> ..................... Search Text: <index-item> <index-entry>APOE e4 variant</index-entry> <pageId>18</pageId> </index-item> <index-item> <index-entry>arousal disorders</index-entry> <see href="c-86679-1" label="see">disorders of arousal</see> </index-item> <index-item> <index-entry>arterial blood gas tests</index-entry> <pageId>32</pageId> </index-item> <index-item> <index-entry>asthma</index-entry> <pageId>28--9, 295</pageId> </index-item> Correct Replacement Text should be: <index-item> <index-entry pages="18">APOE e4 variant</index-entry> </index-item> <index-item> <index-entry>arousal disorders</index-entry> <see href="c-86679-1" label="see">disorders of arousal</see> </index-item> <index-item> <index-entry pages="32">arterial blood gas tests</index-entry> </index-item> <index-item> <index-entry pages="28--29,295">asthma</index-entry> </index-item> Kanhaiya _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs