in reply to How does this regex not match?

If you are having trouble figuring out what the previous responses are saying, the regex my_stuff[1] is equivalent to the regex my_stuff1, which does not appear in your original string.

The regex my_stuff[1] says to look for the string 'my_stuff' followed by one of the characters specified in the brackets. Because you only have one character specified in the brackets, the regex is equivalent to mystuff1.

Here is an example of how brackets can prove useful in a regex:

use strict; use warnings; use 5.010; my $pattern = 'x[ABC]'; my @strings = ( 'xA', 'xB', 'xC', 'xY', ); for (@strings) { if (/$pattern/) { say; } } --output:-- xA xB xC

In order to literally match any of the regex characters that have special meaning (e.g. * . ?), you have to 'escape' the character. You 'escape' a special character with a '\', which tells perl to ignore the special regex meaning of the character. As it turns out, you only have to escape the opening bracket, and then perl knows the closing bracket is to be interpreted as a literal bracket:

use strict; use warnings; use 5.010; my $string= 'my_stuff[1]=400'; my $pattern = 'my_stuff\[1]='; say "They match." if $string =~ /$pattern/; --output:-- They match.