title: Search a specific string in lines and than do a substr at this point in PERL
body: <p>I would like to search in a line for a string. After I found this string, I want to do a substr in that in order get ID. Here an example.</p>
  
  <p>String <code>Testname Testfile 21345 Anfragekennziffer 4519349 Teststring</code></p>
  
  <ul>
  <li>so, in this case I would like the script to catch the string "Anfragekennziffer" and to get the ID, which is here: <code>4519349</code>.</li>
  </ul>
  
  <p>I wrote a script so far, that get me the Ids but only if "Anfragekennziffer" is at the beginning in a line. E.g:</p>
  
  <pre><code>line 1 "Anfragekennziffer4586268" result: "4586268"
  line 2 "Anfragekennziffer5686797" result: "5686797"
  </code></pre>
  
  <p>E.G.</p>
  
  <p>An input file could have the following content:</p>
  
  <pre><code>da adad Anfragekennziffer 6797456
  dadad  Anfragekennziffer6453914
  dasdssss Anfragekennziffer6797433
  dddsaaa Anfragekennziffer6609572
  aaa Anfragekennziffer2435282
  Anfragekennziffer 1234567
  Anfragekennziffer21415666
  </code></pre>
  
  <p>My script (see below) would get the following result:</p>
  
  <pre><code>'nnziffer6','nziffer645','ennziffer6','nnziffer66','ffer243528','1234567','21415666'
  </code></pre>
  
  <p>So, I would like the script to start at "Anfragekennziffer" and get me the ID - npo matter where Anfragekennziffer is located in the line.</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>#!/usr/bin/perl
  use strict;
  use warnings;
  no warnings 'uninitialized';
  
  my $Source = "Anfragekennziffer.txt";
  my $SQL1 = "SQL_Confluence_Tabelle.txt";
  my $SQL2 = "SQL_Provider_Antwort.txt";
  my $time = localtime;
  
  print "\n";
  print "Local date and time: $time\n";
  print "\n";
  print "IDs wurden übertragen.\n";
  print "Folgende SQL-Statements wurden erstellt:\n";
  print "\n";
  print "'SQL_Confluence_Tabelle'\n";
  print "'SQL_Provider_Antwort'\n";
  print "\n";
  
  open(QUELLE, "$Source") or die "Open failed:$!";
  open(ZIEL1, "&gt;$SQL1") or die "Open failed:$!";
  open(ZIEL2, "&gt;$SQL2") or die "Open failed:$!";
  
  my $ids;
  my $weg;
  
  while(my $row = &lt;QUELLE&gt;)
  {
      if ($row =~m/Anfragekennziffer/)
      {
          $row=substr($row,17,10); #gebe nur IDs aus
          $row=~ s/^\s+|\s+$//g; #löscht Leerzeichen
          $ids=$ids."'".$row."',"; #kumuliere IDs
          $ids=~ s/\r|\n//g;
      }
  }
  $weg=chop($ids);
  
  print ZIEL1 "$ids";
  
  print ZIEL2 "$ids";
  close(QUELLE); 
  close(ZIEL1); 
  close(ZIEL2);
  </code></pre>
  
  <p>Would be great if someone  would have an idea!</p>
  
  <p>THANKS!</p>