Here's an approach. File ask_to_replace_1.pl:

use warnings; use strict; my $string = 'Three, Four, One, Two, xFive9, six, Seven'; my $number = qr{ \b [[:upper:]] [[:lower:]]+ \b }xms; print qq{string is now '$string' \n}; my $ordinal = 0; $string =~ s{ ($number) } { ask_replace(++$ordinal, $-[1], $1) }xmsge; print qq{new string is '$string' \n}; print qq{done! \n}; sub ask_replace { my ($ordinal, $offset, $string, ) = @_; my $yes = qr{ (?i) y (?: e (?: s)? )? }xmso; my $ok = qr{ (?i) o (?: k)? }xmso; my $accept = qr{ \A (?: $yes | $ok) \Z }xmso; print qq{sub-string $ordinal at offset $offset is '$string' \n}; print qq{is this correct? }; my $answer = <stdin>; return $string if $answer =~ $accept; print qq{no: enter new string: }; chomp(my $replace = <stdin>); return $replace; }

Output:

c:\@Work\Perl\monks\Keystone>perl ask_to_replace_1.pl string is now 'Three, Four, One, Two, xFive9, six, Seven' sub-string 1 at offset 0 is 'Three' is this correct? n no: enter new string: Uno sub-string 2 at offset 7 is 'Four' is this correct? No no: enter new string: Dos sub-string 3 at offset 13 is 'One' is this correct? y sub-string 4 at offset 18 is 'Two' is this correct? x no: enter new string: Tres sub-string 5 at offset 36 is 'Seven' is this correct? n no: enter new string: se7en new string is 'Uno, Dos, One, Tres, xFive9, six, se7en' done!

In reply to Re: RegExp substitution by AnomalousMonk
in thread RegExp substitution by Keystone

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.