I am trying to match a regex in Perl. My code is as follows:
my $source = "Hello_[version]; Goodbye_[version]"; my $pattern = "Hello_[version]"; if ($source =~ m/$pattern/) { print "Match found!" }
The problem is that the class of characters is indicated in brackets (or so I read) when Perl tries to match the regular expression, and the match fails. I know that I can escape the brackets with \[ or \] , but this will require another block of code to traverse the line and search for the braces. Is there any way that parentheses are automatically ignored without leaving them individually?
Quick note: I can't just add a backslash, as this is just an example. In my true code, $source and $pattern both come from outside Perl code (either URIEncoded, or from a file).
source share