You came into #perl on EFNET and didn't wait too long for a response. Here's something that may get you started. I'm sure it can be fine-tuned, as this is something I whipped up in about 5-10 minutes.
my @badwords = ( '31337', 'hacker' ); my @exceptions = ( 'perl_31337_hacker', ); my $string = 'I am a 31337 hacker. A perl_31337_hacker, that is, not a + c_31337_hacker.'; my @occurences = (); my ($word, $oldword, $badword); foreach $word (@badwords) { push(@occurences, $string =~ /\b\S*$word\S*\b/g); } my %exceptions; @exceptions{@exceptions} = @exceptions; foreach $word (@occurences) { if ( !exists ($exceptions{$word}) ) { $oldword = $word; foreach $badword ( @badwords ) { $word =~ s/$badword/<censored>/g; } $string =~ s/$oldword/$word/; } } print $string;
Output:
I am a <censored> <censored>. A perl_31337_hacker, that is, not a c_<c +ensored>_<censored>.
e-Motion

In reply to Re: Defenetly a complicated perl recipie with 2 arrays, 1 scaler and some special matching by Anonymous Monk
in thread Defenetly a complicated perl recipie with 2 arrays, 1 scaler and some special matching by Anonymous Monk

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.