TASK #1: Count Vowel
You are given a string.
Write a script to return all possible vowel substrings in the given string.
A vowel substring is a substring that only consists of vowels and has all
five vowels present in it.
A Lesson in Word Construction Inspired by the work of the 18th-century music theorist Heinrich Christoph Koch (1749–1816), who described the extension of melodic cells through techniques such as repetition (varied or unvaried), external expansion (via prefixes and suffixes), and internal expansion (such as interpolated "by-the-way" insertions). 1. Prefix / Cell / Suffix Model The central idea behind the Prefix / Cell / Suffix Model is that a word may contain a vowel cell - a core vowel structure - embedded inside a larger string environment. The surrounding material - the prefix and suffix, if present - is structurally secondary. What matters is the internal integrity of the vowel cell itself. This leads naturally to a three-part model: (prefix*) — [ vowel-cell ] — (suffix*) The vowel-cell is defined as a contiguous vowel region satisfying one essential condition: all five vowels {a,e,i,o,u} must occur at least once. Unlike traditional pattern matching, the order of vowels is not fixed. The cell may therefore appear as: aeiou, eioua, uoiea, aaeeeiioouu All of these are structurally equivalent insofar as they preserve vowel completeness within a single continuous formation. The important structural distinction is therefore not between correct and incorrect order, but between: - an incomplete vowel region, - and a complete vowel region. This shifts the perspective from permutation logic to generative construction: a unit is defined by its capacity for completeness rather than by its internal sequence. 2. The Cell as a Reusable Construction Unit Once a complete vowel region exists, it may function as a reusable compositional cell. The cell may: - repeat, - absorb additional vowels at its boundaries (prefix, suffix). - or expand internally (interpolated insertion within the unit), Examples: aeiouaeiou, aaeeeiouu, uaeiou, aeiiou A non-vowel character breaks the continuity of the cell and therefore creates a new structural region: aeiouXaeiou This is interpreted as: - cell 1 = 'aeiou' - separator = 'X' - cell 2 = 'aeiou' Thus the cell behaves like a local vowel-completeness domain embedded inside a larger string. 3. Connection to the Perl Solution The Perl solution mirrors this theoretical model directly. Instead of tracking explicit permutations, the program tracks the presence of vowel features using a compact bitmask representation. Each vowel corresponds to one bit: a=1, e=2, i=4, o=8, u=16 A contiguous vowel region ("cell") accumulates these values. a e i o u -> 1 + 2 + 4 + 8 + 16 = 31 So: $mask == 31 means the current vowel-cell contains all five vowels. The algorithm does not care: - how many times a vowel occurs, - in which order it occurs, - or how large the cell becomes. It only asks: has the cell accumulated the full vowel set? The model treats vowel regions not as fixed sequences, but as structures defined by completeness. # Perl solution #!/usr/bin/perl use strict; use warnings; sub count_vowel { my $s = lc shift; my @res; return @res if $s =~ /[^a-z]/i || $s !~ /^(?=.*a)(?=.*e)(?=.*i)(?=.*o)(?=.*u)/i;# Each vowel is treated as a "feature". # We encode each feature as a bit: my %b = ( a => 1, e => 2, i => 4, o => 8, u => 16 ); my $n = length($s);# We try every possible starting position of a "cell" # (a cell = a continuous block of vowels) for my $i (0 .. $n - 1) { my $mask = 0;# Tracks which vowels we have seen in this cell # Extend the cell to the right step by step for my $j ($i .. $n - 1) { my $c = substr($s, $j, 1);# If we hit a non-vowel, the cell is broken last if !exists $b{$c};# Mark this vowel as "seen" # (bitwise OR means we keep previous vowels too) $mask |= $b{$c};# If all vowels are present, this is a valid cell if ($mask == 31) { push (@res, "'" . substr($s, $i, $j - $i + 1) . "'");# IMPORTANT: # We do NOT stop here, because longer expansions # of the same cell are also valid. } } } return @res; } # TESTS my $str; # Example 1 $str = "aeiou"; print "(", join(", ", count_vowel($str)), ")\n";# Output: ("aeiou") # Example 2 $str = "aaeeeiioouu"; print "(", join(", ", count_vowel($str)), ")\n";# Output: ("aaeeeiioou", "aaeeeiioouu", "aeeeiioou", "aeeeiioouu") # Example 3 $str = "aeiouuaxaeiou"; print "(", join(", ", count_vowel($str)), ")\n";# Output: ("aeiou", "aeiou", "eiouua", "aeiouu", "aeiouua") # Example 4 $str = "uaeiou"; print "(", join(", ", count_vowel($str)), ")\n";# Output: ("aeiou", "uaeio", "uaeiou") # Example 5 $str = "aeioaeioa"; print "(", join(", ", count_vowel($str)), ")\n";# Output: ()