What will be the output ? my $pattern = '.*'; $str =~ /(\Q$pattern\E)/;
-
any number of any characters
-
any number of any characters surrounded by Q and E
-
literally \Q.*\E
-
literally .*
The \Q...\E escape sequence in regex patterns treats everything between as literal text, not regex metacharacters. So /(\Q$pattern\E)/ looks for the literal string '.' (two characters: dot and star), not 'any number of any characters'. The matched value would be '.' if found in $str. Option A incorrectly describes the unescaped behavior of .* as a regex wildcard.
The \Q...\E construct in Perl regexes disables metacharacter interpretation for everything between them, so even though $pattern holds the regex metacharacters .*, quoting it with \Q$pattern\E makes the engine match those two characters literally rather than treating . and * as wildcard/repetition operators.