You tried:     $string !~ s/\d{10}//g; and asked "why can't I just reverse it?" What you wrote did reverse something. But, as you say, not what you intended.

What you wrote means, "do s/\d{10}//g and then return success if it failed." Although that sounds a little funny and is not what you intended, it could actually be useful. Perhaps this will help you conceptualize what is happening:

if ($string !~ s/\d{10}//g) { print "String unchanged: couldn't find 10 digits.\n"; # do stuff to deal with regex failure } else { print "All cases of 10 digits have been deleted.\n"; }
Of course if we really wanted that effect, we would probably want to avoid the easy-to-miss "!" and say either of the following:
if (not $string =~ s/\d{10}//g) { unless ($string =~ s/\d{10}//g) {
To achieve what you wanted, check out the other responses which have offered good solutions.

------------------------------------------------------------
"Perl is a mess and that's good because the
problem space is also a mess.
" - Larry Wall


In reply to Re: Regular Expression Fun by dvergin
in thread Regular Expression Fun by perlfever

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.