@badwords can't contain both regexps and words. For example, your solution will fail with words (e.g.
f*ck won't work), mine will fail with regexps (e.g.
f[u*]ck won't work). I assumed you wanted words since your called your array @badwords.
Both solutions are fine (although the name @badwords is a bit misleading if it contains regexps) depending on what is needed.