sub compatible { my (\$s1, \$s2) = @_; \$s1=~/\G_/gcs and \$s2=~/./gcs or \$s1=~/./gcs and \$s2=~/\G_/gcs or return 0 until \$s1=~/\G\z/ or \$s2=~/\G\z/; 1; } print(compatible("_8__3__19", "4_8___7__") ? "true\n" : "false\n"); ##```## sub compatible { my (\$s1, \$s2) = @_; my \$t; \$s1=~/\G_/gcs and \$s2=~/./gcs or \$s1=~/(.)/gcs and \$t = \$1, \$s2=~/\G_/gcs or \$s2=~/(.)/gcs and \$t eq \$1 or return 0 until \$s1=~/\G\z/ or \$s2=~/\G\z/; 1; } printf "%s v %s ? %s\n", @\$_, compatible( @\$_ ) ? 1 : 0 for [ qw[ _8__3__19 48____7__ ] ], # compat [ qw[ _8__3__19 4_8___7__ ] ], # compat [ qw[ _8__3__19 48_____7_ ] ]; # clash ##``````## sub compatible { my (\$s1, \$s2) = @_; my(\$c1, \$c2, \$d); { \$s1 =~ /(.)/gs or return 1; \$c1 = \$1; \$s2 =~ /(.)/gs or return 1; \$c2 = \$1; if (\$c1 eq "_") { if (\$c2 eq "_") { } else { vec(\$d, ord \$c2, 1)++ and return; } } else { if (\$c2 eq "_") { vec(\$d, ord \$c1, 1)++ and return; } else { \$c1 ne \$c2 and return; vec(\$d, ord \$c2, 1)++ and return; } } redo; } } printf "%s v %s ? %s\n", @\$_, compatible( @\$_ ) || 0 for [ qw[ _8__3__19 48____7__ ] ], # compat [ qw[ _8__3__19 4_2___7__ ] ], # compat [ qw[ _8__3__19 4_8___7__ ] ], # clash [ qw[ __8_3__19 48____7__ ] ], # clash [ qw[ __8_3__19 84____7__ ] ], # clash [ qw[ _8__3__19 48_____7_ ] ]; # clash ```