Use Benchmark when in doubt. YMMV. The first thing I would do for speeding that up is adding a + after the character class, but below proves I'm wrong.

$ cat test.pl #!/pro/bin/perl use strict; use warnings; use Benchmark "cmpthese"; my $string = pack "A*" => map { chr (32 + int rand 95) } 0..1280; cmpthese (-1, { subsingle => '(my $s = $string) =~ s/[^a-zA-Z0-9 _-]//g', subplus => '(my $s = $string) =~ s/[^a-zA-Z0-9 _-]+//g', tran => '(my $s = $string) =~ tr/a-zA-Z0-9 _-//cd', }); $ perl5.8.8 test.pl Rate tran subplus subsingle tran 5938537/s -- -1% -2% subplus 5983722/s 1% -- -1% subsingle 6052802/s 2% 1% -- $ perl5.10.1 test.pl Rate tran subplus subsingle tran 5242880/s -- -2% -5% subplus 5344683/s 2% -- -3% subsingle 5531478/s 6% 3% -- $ perl5.12.3 test.pl Rate tran subplus subsingle tran 5044286/s -- -2% -4% subplus 5144881/s 2% -- -2% subsingle 5242880/s 4% 2% -- $ perl5.14.1 test.pl Rate tran subplus subsingle tran 5144881/s -- -9% -10% subplus 5663605/s 10% -- -1% subsingle 5716536/s 11% 1% -- $

Enjoy, Have FUN! H.Merijn

In reply to Re^2: Remove all non alphanumeric characters excluding space, underscore and minus sign by Tux
in thread Remove all non alphanumeric characters excluding space, underscore and minus sign by ikkeniet

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.