The regex you're using is matching a "word character", i.e. any alphanumeric character and underscore, or a single quote, and as much of them in a row as possible. If you want it to match also a dash, you should say so:
$string =~ /((\w|'|-)+)/g
But that's bit un-regex-like. You should use a character class in this situation:
$string =~ /([-\w']+)/g
But this also matches dashes and apostrophes at the beginnings or ends of words, which may or may not be what you want. If not, you could force that a dash or apostrophe is between alphanumeric characters:
$string =~ /(\w+[-']?\w+)/g
But this has the unwanted effect that a word is at least 2 characters. So we can add an alternation, saying that we also allow a single character word (or number) if we can't match a word consisting of an alphanumerics with a dash or apostrophe between them:
$string =~ /(\w+[-']?\w+|\w)/g
A small complete test-case:
#!/usr/local/bin/perl use strict; use warnings; $/ = undef; my $string = <DATA>; while ($string =~ /(\w+[-']?\w+|\w)/g) { print "Word: <$1>\n"; } __DATA__ This is a sentence with words that're different from other words. They have apostrophes in them (') and dashes, or dash-like characters (-).
Try running this code and compare the output with the sentence in the __DATA__ section.

The ultimate guide (in my opinion) on regular expressions is Jeffrey Friedl's Mastering Regular Expressions, 2nd Edition.

Arjen


In reply to Re: Regexp explanation by Aragorn
in thread Regexp explanation 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.