Perl Weekly Challenge 364.
My solutions (task 1 and task 2 ) to the The Weekly Challenge - 364.
Task 1: Decrypt String
Submitted by: Mohammad Sajid Anwar
You are given a string formed by digits and ‘#'.
Write a script to map the given string to English lowercase
characters following the given rules.
- Characters 'a' to 'i' are represented by '1' to '9'
respectively.
- Characters 'j' to 'z' are represented by '10#' to '26#'
respectively.

Example 1
Input: $str = "10#11#12"
Output: "jkab"
10# -> j
11# -> k
1 -> a
2 -> b

Example 2
Input: $str = "1326#"
Output: "acz"
1 -> a
3 -> c
26# -> z

Example 3
Input: $str = "25#24#123"
Output: "yxabc"
25# -> y
24# -> x
1 -> a
2 -> b
3 -> c

Example 4
Input: $str = "20#5"
Output: "te"
20# -> t
5 -> e

Example 5
Input: $str = "1910#26#"
Output: "aijz"
1 -> a
9 -> i
10# -> j
26# -> z

I can make a simple regular expression to recognize pairs of digits
followed by ‘#’. I can use the /e option to substitute them using a
Perl hash. Finally, I interpret any remaining digits as single
digits. To prepare the hash I take advantage of Perl’s syntax, that
allows evaluating a hash on a list to produce an array that can be
assigned to. The code takes a 1.5-liner.
Examples:
perl -E '
@m{1..9,map"$_\#",10..26}=("a".."z");for(@ARGV){$i=$_;s/(\d\d\#)/$m{$1}/eg;
s/(\d)/$m{$1}/eg;say "$i -> $_"}
' "10#11#12" "1326#" "25#24#123" "20#5" "1910#26#"
Results:
10#11#12 -> jkab
1326# -> acz
25#24#123 -> yxabc
20#5 -> te
1910#26# -> aijz
The full code is:
1 # Perl weekly challenge 364
2 # Task 1: Decrypt String
3 #
4 # See https://wlmb.github.io/2026/03/08/PWC364/#task-1-decrypt-string
5 use v5.36;
6 use feature qw(try);
7 die <<~"FIN" unless @ARGV;
8 Usage: $0 S0 S1...
9 to decrypt the strings Sn, mapping
10 10# to 26# into j..z and 1 to 9 into a..i
11 FIN
12 my %map;
13 @map{(1..9), (map "$_\#", 10..26)} = ("a".."z");
14 for(@ARGV){
15 try {
16 my $in=$_;
17 die "Invalid code: $in" unless /^(\d|\#)*$/; # only digits and hash marks
18 s/(\d\d\#)(?{defined $map{$1}||die "Invalid code: $in"})/$map{$1}/eg;
19 s/(\d)/$map{$1}/eg;
20 die "Invalid code: $in" unless /^[a-z]*$/; # everything converted
21 say "$in -> $_"
22 }
23 catch($e){ warn $e; }
24 }
Example:
./ch-1.pl "10#11#12" "1326#" "25#24#123" "20#5" "1910#26#"
Results:
10#11#12 -> jkab
1326# -> acz
25#24#123 -> yxabc
20#5 -> te
1910#26# -> aijz
Examples with invalid inputs:
./ch-1.pl "abc" "66#"
Results:
Wrong string: abc at ./ch-1.pl line 18.
Wrong code: 66# at ./ch-1.pl line 19.
Task 2: Goal Parser
Submitted by: Mohammad Sajid Anwar
You are given a string, $str.
Write a script to interpret the given string using Goal Parser.
The Goal Parser interprets “G” as the string “G”, “()” as the
string “o”, and “(al)” as the string “al”. The interpreted
strings are then concatenated in the original order.
Example 1
Input: $str = "G()(al)"
Output: "Goal"
G -> "G"
() -> "o"
(al) -> "al"

Example 2
Input: $str = "G()()()()(al)"
Output: "Gooooal"
G -> "G"
four () -> "oooo"
(al) -> "al"

Example 3
Input: $str = "(al)G(al)()()"
Output: "alGaloo"
(al) -> "al"
G -> "G"
(al) -> "al"
() -> "o"
() -> "o"

Example 4
Input: $str = "()G()G"
Output: "oGoG"
() -> "o"
G -> "G"
() -> "o"
G -> "G"

Example 5
Input: $str = "(al)(al)G()()"
Output: "alalGoo"
(al) -> "al"
(al) -> "al"
G -> "G"
() -> "o"
() -> "o"
I simply replace all tokens by their interpretation. This may be done in a half-liner.
Examples:
perl -E '
for(@ARGV){$i=$_; s/\(\)/o/g;s/\(al\)/al/g; say "$i -> $_ "}
' "G()(al)" "G()()()()(al)" "(al)G(al)()()" "()G()G" "(al)(al)G()()"
Results:
G()(al) -> Goal
G()()()()(al) -> Gooooal
(al)G(al)()() -> alGaloo
()G()G -> oGoG
(al)(al)G()() -> alalGoo
The full code is:
1 # Perl weekly challenge 364
2 # Task 2: Goal Parser
3 #
4 # See https://wlmb.github.io/2026/03/08/PWC364/#task-2-goal-parser
5 use v5.36;
6 use feature qw(try);
7 die <<~"FIN" unless @ARGV;
8 Usage: $0 S0 S1...
9 to parse the strings Sn with the Goal Parser.
10 FIN
11 for(@ARGV){
12 try{
13 my $in=$_;
14 die "Wrong format: $in" unless /^(G|\(\)|\(al\))*$/;
15 s/\(\)/o/g;
16 s/\(al\)/al/g;
17 say "$in -> $_ ";
18 }
19 catch($e){ warn $e }
20 }
Example:
./ch-2.pl "G()(al)" "G()()()()(al)" "(al)G(al)()()" "()G()G" "(al)(al)G()()"
Results:
G()(al) -> Goal
G()()()()(al) -> Gooooal
(al)G(al)()() -> alGaloo
()G()G -> oGoG
(al)(al)G()() -> alalGoo
/;
Written on March 8, 2026