Multiple choice technology programming languages

What will be the output ? my $pattern = '.*'; $str =~ /(\Q$pattern\E)/;

  1. any number of any characters

  2. any number of any characters surrounded by Q and E

  3. literally \Q.*\E

  4. literally .*

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

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.

AI explanation

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.