#!/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