title: Perl - Regex to extract only the comma-separated strings
body: <p>I have a question I am hoping someone could help with...</p>
  
  <p>I have a variable that contains the content from a webpage (scraped using WWW::Mechanize). </p>
  
  <p>The variable contains data such as these: </p>
  
  <pre><code>$var = "ewrfs sdfdsf cat_dog,horse,rabbit,chicken-pig"
  $var = "fdsf iiukui aawwe dffg elephant,MOUSE_RAT,spider,lion-tiger hdsfds jdlkf sdf"
  $var = "dsadp poids pewqwe ANTELOPE-GIRAFFE,frOG,fish,crab,kangaROO-KOALA sdfdsf hkew"
  </code></pre>
  
  <p>The only bits I am interested in from the above examples are:</p>
  
  <pre><code>@array = ("cat_dog","horse","rabbit","chicken-pig")
  @array = ("elephant","MOUSE_RAT","spider","lion-tiger") 
  @array = ("ANTELOPE-GIRAFFE","frOG","fish","crab","kangaROO-KOALA")
  </code></pre>
  
  <p><strong>The problem I am having:</strong></p>
  
  <p>I am trying to extract only the comma-separated strings from the variables and then store these in an array for use later on.</p>
  
  <p>But what is the best way to make sure that I get the strings at the start (ie cat_dog) and end (ie chicken-pig) of the comma-separated list of animals as they are not prefixed/suffixed with a comma.</p>
  
  <p><strong>Also</strong>, as the variables will contain webpage content, it is inevitable that there may also be instances where a commas is <strong>immediately succeeded by a space and then another word</strong>, as that is the correct method of using commas in paragraphs and sentences...</p>
  
  <p>For example:</p>
  
  <pre><code>Saturn was long thought to be the only ringed planet, however, this is now known not to be the case. 
                                                       ^        ^
                                                       |        |
                                      note the spaces here and here
  </code></pre>
  
  <p>I am not interested in any cases where the comma is followed by a space (as shown above).</p>
  
  <p><strong>I am only interested in cases where the comma DOES NOT have a space after it (ie cat_dog,horse,rabbit,chicken-pig)</strong></p>
  
  <p>I have a tried a number of ways of doing this but cannot work out the best way to go about constructing the regular expression.</p>