#!/usr/bin/perl -w use strict; # Set up my @charsets = ( [ "b", "h" ], [ "e" ], [ "l", "p", "i" ], [ "l" ], [ "o" ], ); # Do it my @words = (""); for my $char_ref (@charsets) { my @temp_words; for my $word_part (@words) { for my $char (@$char_ref) { push @temp_words, $word_part . $char; } } @words = @temp_words; } # Show it print "$_\n" for @words;