title: Perl Inserting string into a url at specific places
body: <p><strong>I have the following piece of code:</strong></p>
  
  <pre><code>#!/usr/bin/perl
  
  use strict;
  use warnings;
  #use diagnostics;
  
  use URI qw( );
  
  my @insert_words = qw(HELLO GOODBYE);  
  
  while (&lt;DATA&gt;) {
     chomp;
     my $url = URI-&gt;new($_);
     my $query = $url-&gt;query;
  
  foreach (@insert_words) {
    # Use package vars to communicate with /(?{})/ blocks.
    local our $insert_word = $_;
  
    local our @queries;
    if (defined $query) {
        $query =~ m{
            ^(.*[/=])([^/=&amp;]*)((?:[/=&amp;].*)?)\z
            (?{
                if (length $2) {
              push @queries, "$1$insert_word$2$3";
                    push @queries, "$1$insert_word$3";
                    push @queries, "$1$2$insert_word$3";
                }
            })
            (?!)
        }x;
    }
  
        if (@queries) {
            for (@queries) {
                $url-&gt;query($_);
                print $url, "\n";
            }
        }
        else {
            print $url, "\n";
        }
    }
  }
  
  
  __DATA__
  http://www.example.com/index.php?route=9&amp;other=7
  </code></pre>
  
  <p><strong>The above piece of code works correctly and produces the following output:</strong></p>
  
  <pre><code>http://www.example.com/index.php?route=9&amp;other=HELLO7
  http://www.example.com/index.php?route=9&amp;other=HELLO
  http://www.example.com/index.php?route=9&amp;other=7HELLO
  http://www.example.com/index.php?route=HELLO9&amp;other=7
  http://www.example.com/index.php?route=HELLO&amp;other=7
  http://www.example.com/index.php?route=9HELLO&amp;other=7
  http://www.example.com/index.php?route=9&amp;other=GOODBYE7
  http://www.example.com/index.php?route=9&amp;other=GOODBYE
  http://www.example.com/index.php?route=9&amp;other=7GOODBYE
  http://www.example.com/index.php?route=GOODBYE9&amp;other=7
  http://www.example.com/index.php?route=GOODBYE&amp;other=7
  http://www.example.com/index.php?route=9GOODBYE&amp;other=7
  </code></pre>
  
  <p>As you can see it inserts the words in the array at specific places in the url.</p>
  
  <p><strong>What I am now having problems with:</strong></p>
  
  <p>I would now like to add the functionality to do all the possible combinations of <code>HELLO</code> and <code>GOODBYE</code> (or whatever is in the <code>@insert_words</code>) as well, for example it should also add the following url's to the output I already get:</p>
  
  <pre><code>http://www.example.com/index.php?route=HELLO&amp;other=GOODBYE
  http://www.example.com/index.php?route=HELLO&amp;other=HELLO
  http://www.example.com/index.php?route=GOODBYE&amp;other=HELLO
  http://www.example.com/index.php?route=GOODBYE&amp;other=GOODBYE
  </code></pre>
  
  <p>But I do not know how to go about this in the best way?</p>
  
  <p>Your help with this will be much appreciated, many thanks</p>