Perl Weekly Challenge 369.

My solutions (task 1 and task 2 ) to the The Weekly Challenge - 369.

Task 1: Valid Tag

Submitted by: Mohammad Sajid Anwar
You are given a given a string caption for a video.

Write a script to generate tag for the given string caption
in three steps as mentioned below:

1. Format as camelCase
   Starting with a lower-case letter and capitalising the first
   letter of each subsequent word.  Merge all words in the
   caption into a single string starting with a #.

2. Sanitise the String
   Strip out all characters that are not English letters
   (a-z or A-Z).
3. Enforce Length
   If the resulting string exceeds 100 characters, truncate
   it so it is exactly 100 characters long.

Example 1
Input: $caption = "Cooking with 5 ingredients!"
Output: "#cookingWithIngredients"

Example 2
Input: $caption = "the-last-of-the-mohicans"
Output: "#thelastofthemohicans"

Example 3
Input: $caption = "  extra spaces here"
Output: "#extraSpacesHere"

Example 4
Input: $caption = "iPhone 15 Pro Max Review"
Output: "#iphoneProMaxReview"

Example 5
Input: $caption = "Ultimate 24-Hour Challenge: Living in a
                   Smart Home controlled entirely by
                   Artificial Intelligence and Voice
                   Commands in the year 2026!"
Output: "#ultimateHourChallengeLivingInASmartHomeControlledEntirelyByArtificialIntelligenceAndVoiceCommandsIn"


I assume the words are space separated. I first throw away leading space. Then I separate the words, capitalize the first letter of each word but the first, which is lowercased, join them, remove non-English letters, append a hash and truncate. The result fits a 1.5-liner.

Examples:

perl -E '
for(@ARGV){$i=$_; s/^\s*//;($f,@r)=split" ";$r=join"",lc($f),map{ucfirst}@r;$r=~tr/a-zA-Z//cd;
$r=substr "#$r", 0, 100;say"$i -> $r"}
' "Cooking with 5 ingredients!" "the-last-of-the-mohicans" \
  "  extra spaces here" "iPhone 15 Pro Max Review" \
  "Ultimate 24-Hour Challenge: Living in a Smart Home \
   controlled entirely by Artificial Intelligence and \
   Voice Commands in the year 2026!"

Results:

Cooking with 5 ingredients! -> #cookingWithIngredients
the-last-of-the-mohicans -> #thelastofthemohicans
  extra spaces here -> #extraSpacesHere
iPhone 15 Pro Max Review -> #iphoneProMaxReview
Ultimate 24-Hour Challenge: Living in a Smart Home \
 controlled entirely by Artificial Intelligence and \
 Voice Commands in the year 2026! -> \
 #ultimateHourChallengeLivingInASmartHomeControlledEntirelyByArtificialIntelligenceAndVoiceCommandsIn

The full code is

 1  # Perl weekly challenge 369
 2  # Task 1:  Valid Tag
 3  #
 4  # See https://wlmb.github.io/2026/04/13/PWC369/#task-1-valid-tag
 5  use v5.36;
 6  die <<~"FIN" unless @ARGV;
 7      Usage: $0 S0 S1...
 8      to make a tag our of the strings Sn
 9      FIN
10  for(@ARGV){
11      my $input = $_;
12      s/^\s*//; # Remove leading spaces
13      my ($first, @rest) = split " ";
14      my $joined = join " ",
15          lc($first),
16          map {ucfirst} @rest;
17      $joined =~ tr/a-zA-Z//cd; # remove non-English letters
18      my $result= substr
19          "#$joined",  # append hash
20          0, 100; # and truncate
21      say "$input -> $result";
22  }

Example:

./ch-1.pl "Cooking with 5 ingredients!" "the-last-of-the-mohicans" \
          "  extra spaces here" "iPhone 15 Pro Max Review" \
          "Ultimate 24-Hour Challenge: Living in a Smart Home \
           controlled entirely by Artificial Intelligence and \
           Voice Commands in the year 2026!"

Results:

Cooking with 5 ingredients! -> #cookingWithIngredients
the-last-of-the-mohicans -> #thelastofthemohicans
  extra spaces here -> #extraSpacesHere
iPhone 15 Pro Max Review -> #iphoneProMaxReview
Ultimate 24-Hour Challenge: Living in a Smart Home \
controlled entirely by Artificial Intelligence and \
Voice Commands in the year 2026! ->
#ultimateHourChallengeLivingInASmartHomeControlledEntirelyByArtificialIntelligenceAndVoiceCommandsIn

Task 2: Group Division

Submitted by: Mohammad Sajid Anwar
You are given a string, group size and filler character.

Write a script to divide the string into groups of given
size. In the last group if the string doesn’t have enough
characters remaining fill with the given filler character.

Example 1
Input: $str = "RakuPerl", $size = 4, $filler = "*"
Output: ("Raku", "Perl")

Example 2
Input: $str = "Python", $size = 5, $filler = "0"
Output: ("Pytho", "n0000")

Example 3
Input: $str = "12345", $size = 3, $filler = "x"
Output: ("123", "45x")

Example 4
Input: $str = "HelloWorld", $size = 3, $filler = "_"
Output: ("Hel", "loW", "orl", "d__")

Example 5
Input: $str = "AI", $size = 5, $filler = "!"
Output: "AI!!!"

I use a regular expression to produce a list of all fragments of the desired size, probably followed by an incomplete fragment. I complete the last element with the filler and print the results. The result fits a one-liner.

Examples:

perl -E '
for my($w,$s,$f)(@ARGV){@r=$w=~/(.{$s}|.+)/g;$r[-1].="$f"x($s-length$r[-1]);say"$w, $s, $f -> @r"}
' RakuPerl 4  \* Python 5 0 12345 3 x HelloWorld 3 _ AI 5 !

Results:

RakuPerl, 4, * -> Raku Perl
Python, 5, 0 -> Pytho n0000
12345, 3, x -> 123 45x
HelloWorld, 3, _ -> Hel loW orl d__
AI, 5, ! -> AI!!!

The full code is:

 1  # Perl weekly challenge 369
 2  # Task 2:  Group Division
 3  #
 4  # See https://wlmb.github.io/2026/04/13/PWC369/#task-2-group-division
 5  use v5.36;
 6  use feature qw(try);
 7  die <<~"FIN" unless @ARGV and @ARGV%3==0;
 8      Usage: $0 S0 L0 F0 S1 L1 F1...
 9      to divide the string Ln into pieces of length Ln
10      filling the last one with the filler Fn.
11      FIN
12  for my($string, $size, $filler)(@ARGV){
13      warn("Filler must be one character wide: $filler"), next
14          unless length $filler==1;
15      my @result = $string =~ /(.{$size}|.+)/g;
16      $result[-1] .= "$filler" x ($size - length $result[-1]);
17      say "string=$string, size=$size, filler=$filler -> ",
18          join ", ", map {"\"$_\""} @result;
19  }

Example:

./ch-2.pl RakuPerl 4  \* Python 5 0 12345 3 x HelloWorld 3 _ AI 5 !

Results:

string=RakuPerl, size=4, filler=* -> "Raku", "Perl"
string=Python, size=5, filler=0 -> "Pytho", "n0000"
string=12345, size=3, filler=x -> "123", "45x"
string=HelloWorld, size=3, filler=_ -> "Hel", "loW", "orl", "d__"
string=AI, size=5, filler=! -> "AI!!!"

/;

Written on April 13, 2026