title: Regular Expression to match and split with operator in Perl
body: <p>I need a regular expression that matches exact keywords as well as special characters or operators.</p>
  
  <p>For instance, I have a string and I want to split this with regular expression.</p>
  
  <pre><code> my $data="long i = sbyte.MinValue ; i =&gt; sbyte.MaxValue ; &gt; i++";
  </code></pre>
  
  <p>If I split this on the equals character <code>=</code> then it should return two strings:</p>
  
  <ol>
  <li><p><code>long i</code></p></li>
  <li><p><code>sbyte.MinValue ; i =&gt; sbyte.MaxValue ; &gt; i++</code></p></li>
  </ol>
  
  <p>If I split with <code>=&gt;</code> then it will return:</p>
  
  <ol>
  <li><p><code>long i = sbyte.MinValue ; i</code></p></li>
  <li><p><code>sbyte.MaxValue ; &gt; i++</code></p></li>
  </ol>
  
  <p>Here is the example code:</p>
  
  <pre><code>my $key = "=";
  
  my $data = "long i = sbyte.MinValue ; i =&gt; sbyte.MaxValue ; &gt; i++";
  
  #=~/\b$s\b/
  #/\b$key\b/
  
  my @matches = ( $data =~/\b$key\b/ );
  
  my @string = split (/\b$key\b/, $data); # split ~ /^=$/, $data;
  
  if ( scalar(@string) &gt; 0 ) {
  
      foreach my $item ( @string ) {
          print "$item \n";
      }
  }
  else {
      print "Nothing found \n";
  }
  </code></pre>
  
  <p>The issue comes with an operator to search and split in string.
  Exact match works with keywords or other text, but with operators
  like <code>=</code>, <code>&gt;=</code>, <code>&lt;=</code>, <code>!=</code>, <code>&lt;&lt;=</code>, <code>=&gt;&gt;</code>, <code>++</code>, <code>--</code> it's not working.</p>
  
  <p>I need to search one by one and split the text.</p>