Assuming this is not HTML and thus is appropriate for a simplistic search and replace the following code should get you started:

use warnings; use strict; my $str = <<TEXT; All businesses, regardless of their size, location, or mission, operat +e within a larger external environment. This external environment consists of eve +rything outside an organization&#146;s boundaries that might affect it. Not surprisingly, the external environment plays a major role in determini +ng the success or failure of any organization. Managers must therefore have a + complete and accurate understanding of their environment and then strive to ope +rate and compete within it. Of course, businesses can also influence their envi +ronments. To better explain the environment of business, we begin by discussing organizational boundaries, and then we introduce the concept of multip +le organizational environments. Quite simply, an organizational boundary +is that which separates the organization from its environment.<fref id="fn1"/> + But whereas boundaries were once relatively easy to identify, they are bec +oming increasingly complicated and hard to pin down. Consider the simple cas +e of a small neighborhood grocery that includes a retail customer area, a sto +rage room, and an owner/manager&#146;s office.<fref id="fn2"/> In many ways, the store&#146;s boundary coincides with its physical structure: When you +walk through the door, you&#146;re crossing the boundary into the business, + and when you go back onto the sidewalk, you cross the boundary back into the environment.<fn id="fn1">See Waren J. Keegan, Global Marketing Management</fn><fn id="fn2">See James J. Kellenberger, Global Warming Management</fn> TEXT my @footnotes; push @footnotes, [$1, $2] while $str =~ m|<fn\s+id="(\w+)">((?:(?!</fn +>).)*)</fn>|gms; $str =~ s| <fref\s+id="\Q$_->[0]\E"/> | <footnote id="$_->[0]"$_->[1]<\/para><\/footnote> |gxms for @footnotes; print $str;

Prints:

All businesses, regardless of their size, location, or mission, operat +e within a larger external environment. This external environment consists of eve +rything outside an organization&#146;s boundaries that might affect it. Not surprisingly, the external environment plays a major role in determini +ng the success or failure of any organization. Managers must therefore have a + complete and accurate understanding of their environment and then strive to ope +rate and compete within it. Of course, businesses can also influence their envi +ronments. To better explain the environment of business, we begin by discussing organizational boundaries, and then we introduce the concept of multip +le organizational environments. Quite simply, an organizational boundary +is that which separates the organization from its environment. <footnote id="fn1"See Waren J. Keegan, Global Marketing Management</para></footnote> But whereas boundaries were once relatively easy to identify, they are bec +oming increasingly complicated and hard to pin down. Consider the simple cas +e of a small neighborhood grocery that includes a retail customer area, a sto +rage room, and an owner/manager&#146;s office. <footnote id="fn2"See James J. Kellenberger, Global Warming Management</para></footnote> In many ways, the store&#146;s boundary coincides with its physical structure: When you +walk through the door, you&#146;re crossing the boundary into the business, + and when you go back onto the sidewalk, you cross the boundary back into the environment.<fn id="fn1">See Waren J. Keegan, Global Marketing Management</fn><fn id="fn2">See James J. Kellenberger, Global Warming Management</fn>

The replacement text looks rather broken to me, but that's from an HTML perspective so probably isn't relevant and is easily fixed in any case (probably). The main trick is to generate a list of footnote pairs up front, then perform a global search and replace for each footnote.


DWIM is Perl's answer to Gödel

In reply to Re: Replacing text in a string by GrandFather
in thread Replacing text in a string by rsriram

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.