# https://theweeklychallenge.org/blog/perl-weekly-challenge-340/ use v5.12; use warnings; use Test::More; for my $case ('abbaca','azxxzy','aaaaaaaa','aabccba','abcddcba') { my $str = $case; say "*** Input: $str"; while ( $str =~s/(\w)\1// ) { say "Remove '$&' => '$str'"; } my $exp = $str; say "Expected Output : '$str'"; $str = $case; $str =~ s/((\w)(?1)?\g{-1})//g; say "Got Output : '$str'"; is($exp,$str,"'$case' ->'$str'"); say "...\n" } done_testing() #### *** Input: abbaca Remove 'bb' => 'aaca' Remove 'aa' => 'ca' Expected Output : 'ca' Got Output : 'ca' ok 1 - 'abbaca' ->'ca' ... *** Input: azxxzy Remove 'xx' => 'azzy' Remove 'zz' => 'ay' Expected Output : 'ay' Got Output : 'ay' ok 2 - 'azxxzy' ->'ay' ... *** Input: aaaaaaaa Remove 'aa' => 'aaaaaa' Remove 'aa' => 'aaaa' Remove 'aa' => 'aa' Remove 'aa' => '' Expected Output : '' Got Output : '' ok 3 - 'aaaaaaaa' ->'' ... *** Input: aabccba Remove 'aa' => 'bccba' Remove 'cc' => 'bba' Remove 'bb' => 'a' Expected Output : 'a' Got Output : 'a' ok 4 - 'aabccba' ->'a' ... *** Input: abcddcba Remove 'dd' => 'abccba' Remove 'cc' => 'abba' Remove 'bb' => 'aa' Remove 'aa' => '' Expected Output : '' Got Output : '' ok 5 - 'abcddcba' ->'' ... 1..5