title: Perl Use of uninitialized value in substitution
body: <p>Why is this generating the error:</p>
  
  <p><strong>Use of uninitialized value $match in substitution (s///) at ...</strong></p>
  
  <pre><code>my $sub = 0;  #added
  my $m;  #added
  
  open (FH1, "&lt;FILE1.txt") || die $!;
  open (FH2, "&lt;FILE2,txt") || die $!;
  
  my @strings = (&lt;FH2&gt;);  #each line of the file into an array
  close FH2 or die $!;
  
  my $here;
  while ( my $url = &lt;FH1&gt; ) {
      chomp $url;
  
      foreach my $sub (@strings) {      
           my $repeat = 1; 
           while ((my $m = $_) =~ s|(?&lt;![/])(?:[/](?![/])[^/]*){$repeat}[^/]*\K|$sub|)  #&lt;-- Error states the error is occurring here
           {
  
                print "$m\n";   
                $repeat++;    
  
                push( @{ $here-&gt;{$url} }, $m ); 
           }        
      }
  }
  </code></pre>
  
  <p>There is definitely something in the files (as I can print each of the lines inside the <code>foreach</code> loop) and the regular expression substitution definitely works as it has been tested in its own program before I tried to move it into this program.</p>
  
  <p><strong>Is it something obvious I'm overlooking?</strong></p>
  
  <p>Your help would be much appreciated, many thanks </p>