in reply to Question on REGEXP

| has a special meaning in a regex: it separates alternatives. If you know your variable should not contain any special characters, you can "quote" it by using \Q:
my $id_to_match = '1QJ8:A|PDBID|CHAIN'; while (<>) { if (/\Q$id_to_match/) { # ... } }

See Escape sequences in perlre for details.

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Question on REGEXP
by Anonymous Monk on Mar 10, 2014 at 14:11 UTC
    So this escapes everything, right? I mean, if you want to treat any given character as normal character, without any exceptions/special meanings.
      Yes. If you only want to escape some characters, you can try the hard way: adding \ in front of them in the string. If you want to escape anything in a substring, you can end the effect of \Q by \E.
      /\Q$literal_characters\E$special_characters/
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        or use quotemeta - see perldoc -f quotemeta
        Aha, thanks for the tips :)