in reply to Question on REGEXP

My preferred way to escape a special regex character, e.g the alternation(|) character, is to use a character class:
use strict; use warnings; use 5.014; my $pattern =<<'END_OF_PATTERN'; 1QJ8:A #These characters, followed by... [|] #a literal pipe, followed by... PDBID #these characters, folllowed by... [|] #a literal pipe, followed by... CHAIN #this word END_OF_PATTERN my $str = '1QJ8:A...PDBID....CHAIN...1QJ8:A|PDBID|CHAIN'; my @matches = $str =~ /$pattern/gxms; say "@matches"; --output:-- 1QJ8:A|PDBID|CHAIN