- $c1 = substr $s1, $i, 1;
- my $c2 = length $s2 <= $i ? undef : substr $s2, $i, 1;
- my $next = $i + 1 >= length($s1) ? $c1 : chr( ord($c1) + 1 );
- $next le $c2 or next if defined $c2;
- my $last = defined $c2 && $i == 0 ? chr( ord($c2) - (length $s2 > 1) ) : 'z';
+ my $lasti = $i == length($s1) - 1;
+ $char = substr $s1, $i, 1;
+ my $next = $char;
+ # do not include prefix character in final range
+ $next = chr( ord($char) + 1 ) unless $lasti;
+
+ my $last = 'z';
+ next if $next gt $last;
+ if (length $s2 > $i) {
+ if ($s2 =~ /^\Q$prefix/) {
+ $last = substr $s2, $i, 1;
+ next if $char eq $last;
+ $last = chr( ord($last) - (length $s2 > 1) );
+ next if $next gt $last;
+ }
+ }
+
+ if ($char eq '.') {
+ if ($last eq 'z') {
+# push @allow, $prefix if $i and $lasti;
+# next;
+ }
+# if ($last eq 'z') {
+# push @allow, $prefix if $i and $lasti;
+# next;
+# }
+ $next = 'a';
+ }
+