my $t = 'some path/to/foo/bar\[1\]\[2\]'; my $a = 'bar\\[1'; print "match!\n" if($t =~ m/$a/);