in reply to Matching Character Patterns With Backreferences

I just realized I should probably paste the code I had that generated that.I should mention that $d is the path to the dictionary file (with the words to match) and $p is the input pattern (ABBCDE above).

This is pretty ugly

my %charhash; @letters = split(//,$p); $string = ""; $invert = ""; $count = 1; foreach $letter (@letters) { if(defined $charhash{$letter}) { $string.="(\\$charhash{$letter})"; } else { $charhash{$letter} = $count; if($invert) { $string .= "([^$invert])"; } else { $string .= "(\\w)"; } } $invert .= "\\$count"; $count++; } print "Searching for pattern /^$string\\s/\n"; open DICT, $d; while(<DICT>) { print if /^$string\s/i; }