Perl Weekly Challenge 374.
My solutions (task 1 and task 2 ) to the The Weekly Challenge - 374.
Task 1: Count Vowel
Submitted by: Mohammad Sajid Anwar
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.
Example 1
Input: $str = "aeiou"
Output: ("aeiou")

Example 2
Input: $str = "aaeeeiioouu"
Output: ("aaeeeiioou", "aaeeeiioouu", "aeeeiioou", "aeeeiioouu")
NOTE: Updated output [2025-05-18]

Example 3
Input: $str = "aeiouuaxaeiou"
Output: ("aeiou", "aeiou", "eiouua", "aeiouu", "aeiouua")
NOTE: Updated output [2025-05-18]

Example 4
Input: $str = "uaeiou"
Output: ("aeiou", "uaeio", "uaeiou")

Example 5
Input: $str = "aeioaeioa"
Output: ()

I can separate each string into continuous pieces with no consonant. For each piece, I repeatedly truncate it until it misses some vowel. The code takes a 2.5-liner.
Examples:
perl -E '
sub t($x){$x=~/$_/||return 0 for(split "","aeiou");1}for(@ARGV){my@r;for my$i(/([aeiou]+)/g)
{$l=length$i;for(0..$l){t $r=substr$i,$_ or last;push @r,$r;for(1..$l){t $s=substr$r,0,-$_ or
last;push@r,$s}}}say"$_ -> (@r)";}
' aeiou aaeeeiioouu aeiouuaxaeiou uaeiou aeioaeioa
Results:
aeiou -> (aeiou)
aaeeeiioouu -> (aaeeeiioouu aaeeeiioou aeeeiioouu aeeeiioou)
aeiouuaxaeiou -> (aeiouua aeiouu aeiou eiouua aeiou)
uaeiou -> (uaeiou uaeio aeiou)
aeioaeioa -> ()
A slightly shorter, slightly more inefficient version is:
perl -E '
sub t($x){$x=~/$_/||return 0 for split"","aeiou";1}for(@ARGV){say "$_ -> (", join(", ",map
{$l=length($i=$_);grep{t($_)}map{($j=$_,map {substr $j,0,-$_}(1..$l))}map{substr$i,$_}(0..$l)}
/([aeiou]+)/g), ")";}
' aeiou aaeeeiioouu aeiouuaxaeiou uaeiou aeioaeioa
Results:
aeiou -> (aeiou)
aaeeeiioouu -> (aaeeeiioouu, aaeeeiioou, aeeeiioouu, aeeeiioou)
aeiouuaxaeiou -> (aeiouua, aeiouu, aeiou, eiouua, aeiou)
uaeiou -> (uaeiou, uaeio, aeiou)
aeioaeioa -> ()
The full code is:
1 # Perl weekly challenge 374
2 # Task 1: Count Vowel
3 #
4 # See https://wlmb.github.io/2026/05/22/PWC374/#task-1-count-vowel
5 use v5.36;
6 use feature qw(try);
7 die <<~"FIN" unless @ARGV;
8 Usage: $0 S0 S1...
9 to find all substrings of Sn containing only vowels, and all of them.
10 FIN
11 for(@ARGV){
12 try{
13 die "Expected a lowercase string: $_" unless $_ eq lc $_;
14 my @results;
15 for my $noconsonant(/([aeiou]+)/g){
16 my $maxlength = length $noconsonant;
17 for(0..$maxlength){
18 # truncate from the start
19 test(my $tentative = substr $noconsonant, $_) || last;
20 push @results, $tentative;
21 for(1..$maxlength){
22 # truncate from the end
23 test(my $truncated = substr $tentative, 0, -$_) || last;
24 push @results, $truncated;
25 }
26 }
27 }
28 say "$_ -> (@results)";
29 }
30 catch($e){warn $e}
31 }
32 sub test($x){
33 $x=~/$_/||return 0 for(split "","aeiou");
34 return 1;
35 }
Examples:
./ch-1.pl aeiou aaeeeiioouu aeiouuaxaeiou uaeiou aeioaeioa
Results:
aeiou -> (aeiou)
aaeeeiioouu -> (aaeeeiioouu aaeeeiioou aeeeiioouu aeeeiioou)
aeiouuaxaeiou -> (aeiouua aeiouu aeiou eiouua aeiou)
uaeiou -> (uaeiou uaeio aeiou)
aeioaeioa -> ()
Notice that I shouldn’t worry about truncating too much, as the test would fail anyway.
Task 2: Largest Same-digits Number
Submitted by: Mohammad Sajid Anwar
You are given a string containing 0-9 digits only.
Write a script to return the largest number with all digits
the same in the given string.
Example 1
Input: $str = "6777133339"
Output: 3333

Example 2
Input: $str = "1200034"
Output: 4

Example 3
Input: $str = "44221155"
Output: 55

Example 4
Input: $str = "88888"
Output: 88888

Example 5
Input: $str = "11122233"
Output: 222
In all the examples the same digits are contiguous. Thus, I guess I can split the string into substrings of contiguous digits and take the largest one. This yields a half liner.
Examples:
perl -MList::Util=max -E '
say "$_ -> ", max /((\d)\2*)/g for(@ARGV);
' 6777133339 1200034 44221155 88888 11122233
Results:
6777133339 -> 3333
1200034 -> 4
44221155 -> 55
88888 -> 88888
11122233 -> 222
Notice that /((\d)\2*)/g produces a list of repeated
digits alternating with the single digits that are
repeated. That doesn’t alter the result, as the single
digits are not larger than the repeated digits.
The full code is:
1 # Perl weekly challenge 374
2 # Task 2: Largest Same-digits Number
3 #
4 # See https://wlmb.github.io/2026/05/22/PWC374/#task-2-largest-same-digits-number
5 use v5.36;
6 use List::Util qw(max);
7 die <<~"FIN" unless @ARGV;
8 Usage: $0 S0 S1...
9 to find the largest number made of repetitions of
10 a single digit within the string Sn
11 FIN
12 say "$_ -> ", max /((\d)\2*)/g for(@ARGV);
Example:
./ch-2.pl 6777133339 1200034 44221155 88888 11122233
Results:
6777133339 -> 3333
1200034 -> 4
44221155 -> 55
88888 -> 88888
11122233 -> 222
/;