in reply to Find and replace using regex

Hi rsriram,

Here is one way to do it.

use strict; use warnings; my $str = do { local $/, <DATA> }; my @fnote = qw(<FN1>footnote1</FN1> <FN2>footnote1</FN2> <FN3>footnote +1</FN3>); #Already retrived footnotes my %hash; for (@fnote) { $hash{$1} = $_ if ($_ =~ /<(FN\d+)>/); } $str =~ s|<(FN\d+)ref>|$hash{$1}|g; print $str; __DATA__ <p> Here some text <FN1ref> and some text Here some text <FN2ref> and some text Here some text <FN3ref> and some text </p> <FN1>afsdfsaf</FN1> <FN2>afsdfsaf</FN2> <FN3>afsdfsaf</FN3> outputs: -------- <p> Here some text <FN1>footnote1</FN1> and some text Here some text <FN2>footnote1</FN2> and some text Here some text <FN3>footnote1</FN3> and some text </p> <FN1>afsdfsaf</FN1> <FN2>afsdfsaf</FN2> <FN3>afsdfsaf</FN3>

* My 200th post :)

Prasad