use strict; #the substitution possibilities my @a = ('a'); my @b = ('d','e'); my @c = ('f','g','h'); my $string = pop(@_); #this is an argument passed to the script on the command line #my $string = "abc"; #if you want it hardcoded my $expanded_string = ""; my @strings = (); foreach my $first (@a){ foreach my $second (@b){ foreach my $third (@c){ $string = "$first$second$third"; push(@strings, $string); #to store them all print "$string\n"; #to print this particular one } } }