in reply to combinations of given string
Another approach:
my $str = 'ABC---'; my $dash = $str =~ tr/-//d; my %combo = ($str => 1); %combo = map { my $x = $_; map {$x =~ s/.{$_}\K/-/r, 1} 0..length; } keys %combo for 1..$dash; say for reverse sort keys %combo; __END__ ABC--- AB-C-- AB--C- AB---C A-BC-- A-B-C- A-B--C A--BC- A--B-C A---BC -ABC-- -AB-C- -AB--C -A-BC- -A-B-C -A--BC --ABC- --AB-C --A-BC ---ABC
|
|---|