title: How to multiple search on the same string using regular expression in perl?
body: <p>I need to get the different kinds of information from a website. It is knowing that the format is in this way (all on one line):</p>
  
  <pre><code>"name":"BLAHBLAH","contact":{"phone":"12345","twitter":"BLAHBLAH"},
    "location": "address":"NOTTELLING","lat":10,"lng":10,"postalCode":"1234",
    "city":"BLAH","state":"BLAH","country":"BLAH"},
    "categories":[{"id":"BLAH","name":"BLAH"}]
  </code></pre>
  
  <p>Some of these profiles will have one or two blocks missing, like no name, no city, etc.
  I tried the code like this:</p>
  
  <pre><code>   #get name
     $content =~ m!","name":"(.*?)","contact":!igs;
     say ("name:", $1) unless ($1 eq '');
     #get street 
     if ($content =~ m!\},"location":\{"address":"(.*?)","lat":!igs)
     {say ("street:", $1) unless ($1 eq '');}
     #get city 
     if ($content =~ m!,"city":"(.*?)","state":!igs)
     {say ("city:", $1) unless ($1 eq '');}
     #get state
     if ($content =~ m!,"state":"(.*?)","country":!igs)
     {say ("state:", $1) unless ($1 eq '');}
  </code></pre>
  
  <p>Then I realize that when i use the repeated pattern (e.g. </p>
  
  <pre><code>"city":"(.*?)","state":!igs
  </code></pre>
  
  <p>and</p>
  
  <pre><code>"state":"(.*?)","country":!igs)
  </code></pre>
  
  <p>the result will be not accurate. (I guess perl jump over the string after the first time it gets to ,"state") My question is how this happens? and how do i fix it?</p>