You should consider using s/\D+//g, as that's often a lot faster than s/\D//g. Here's a benchmark:
#!/usr/bin/perl use strict; use warnings; use Benchmark; my @sizes = (10, 25, 50, 100, 250, 500, 1000); my @chars = ('A' .. 'Z', 'a' .. 'z', 0 .. 9); our @d = map {join "" => map {$chars [rand @chars]} 1 .. $_} @sizes; map { Benchmark::cmpthese timethese (-2 => { "simple_$sizes[$_]" => '$_ = $::d[' . $_ . ']; s/\D//g;', "multiple_$sizes[$_]" => '$_ = $::d[' . $_ . ']; s/\D+//g;' }, 'none'); } 0 .. $#sizes __END__ Rate simple_10 multiple_10 simple_10 196495/s -- -15% multiple_10 231225/s 18% -- Rate simple_25 multiple_25 simple_25 89788/s -- -50% multiple_25 180650/s 101% -- Rate simple_50 multiple_50 simple_50 47507/s -- -64% multiple_50 130727/s 175% -- Rate simple_100 multiple_100 simple_100 23206/s -- -77% multiple_100 103096/s 344% -- Rate simple_250 multiple_250 simple_250 10488/s -- -71% multiple_250 36407/s 247% -- Rate simple_500 multiple_500 simple_500 5046/s -- -75% multiple_500 20382/s 304% -- Rate simple_1000 multiple_1000 simple_1000 2528/s -- -76% multiple_1000 10549/s 317% --

Abigail


In reply to Re: Strip non-numeric by Abigail-II
in thread Strip non-numeric by FireBird34

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.