in reply to Negative Lookahead using negated character classes?

regexp is challenging and fun, but not always the best solution, sometime it could be ugly and not maintainable.

In this case, first split on /, to get the prot part, then use the power of bitwise XOR like this (I choose not to use natural language to descibe, you should be able to understand what I am trying to say):

use strict; my $str = "paat"; (my $cmp = $str ^ "prot") =~ s/(.)/ord($1) ? "0" : "1"/eg; print $cmp; #prot => 1111 #pro? => 1110 #pr?? => 1100 #p??? => 1000 #???? => 0000