Using glob or the <> operator looks like the ticket. Consider:
#!/usr/bin/perl -w use strict; print "$_\n" for (<{f}{r,x,y}{e,a,b}{d}>); __END__ program: op's post fred fred frad fxed frbd fyed fxed frad fxad frbd fxbd fxad fyed fxbd fyad fyad fybd fybd
Update: Thought I had x,y and a,b reversed in previous code. Note the order is different than the op's post, but the combinations are the same.

Continuing on.. a straightforward implementation of a sub to generate the glob string is shown below.. took a couple of more steps than I thought it would.

#!/usr/bin/perl -w use strict; my $string = 'fred'; my %substitution = ( 2 => 'xy', 3 => 'ab' ); my @variants = gen_variants($string, %substitution); print join("\n",@variants),"\n"; sub gen_variants { my ($string, %substitution) = @_; my @letters = split(//,$string); foreach my $pos (keys %substitution) { my @newltrs = split(//,$substitution{$pos}); $letters[$pos-1] = join(',',$letters[$pos-1],@newltrs); } @letters = map{"{$_}"}@letters; my $globstr = join('',@letters); print "glob string = $globstr\n"; return (glob($globstr)); } __END__ prints: glob string = {f}{r,x,y}{e,a,b}{d} fred frad frbd fxed fxad fxbd fyed fyad fybd

In reply to Re: String Replace - Permutation, Combination? by Marshall
in thread String Replace - Permutation, Combination? by cbdoc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.