$constraint =~ m@ ^\s* # skip all whitespace at beginning ( /.+/ # capture the custom regex |m(.).+\2 # does this capture the ops? What does the |m do? why is the (.) and \2 in there? ) [cgimosx]* # ?? don't understand what this is for. what are we trying to match? I thought the ops were matched above \s*$ # skip all whitespace at end @x #### my $input = 'http://www.knowmad.com/'; my $constraint_good = '/[\\!@#%&_:\$\^\*\(\)\+\.\/]+/'; my $constraint_bad = '/[!@#%&_:\$\^\*\(\)\+\.\/]+\\/'; if ( $constraint_good =~ m@^\s*(/.+/|m(.).+\2)[cgimosx]*\s*$@ ) { my $sub = eval 'sub { $_[0] =~ '. $constraint_good . '}'; die "Error compiling regular expression $constraint_good: $@" if $@; print "matched\n"; } else { print "no good.\n" } if ( $constraint_bad =~ m@^\s*(/.+/|m(.).+\2)[cgimosx]*\s*$@ ) { my $sub = eval 'sub { $_[0] =~ '. $constraint_bad . '}'; die "Error compiling regular expression $constraint_bad: $@" if $@; print "matched\n"; } else { print "no good.\n" } #### matched Error compiling regular expression /[!@#%&_:\$\^\*\(\)\+\.\/]+\/: Search pattern not terminated at (eval 2) line 1.