Perl MCQ Banner

Perl Multiple Choice Questions (MCQs) and Answers

Master Perl with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of Perl. Begin your placement preparation journey now!

Q31

Q31 What will be the output of my $x = "abc" + 10; print $x;?

A

abc10

B

10

C

Error

D

0

Q32

Q32 Which of the following is a valid conditional statement in Perl?

A

if-else

B

when

C

try-catch

D

foreach

Q33

Q33 What keyword is used to exit a loop prematurely in Perl?

A

stop

B

break

C

exit

D

last

Q34

Q34 Which loop is best for iterating over an array in Perl?

A

while

B

for

C

foreach

D

do-while

Q35

Q35 What is the default condition for an unless statement in Perl?

A

True

B

False

C

Undefined

D

Nonzero

Q36

Q36 What is the purpose of the redo statement in Perl loops?

A

Repeats the loop from the beginning without re-evaluating the condition

B

Exits the loop immediately

C

Skips the next iteration

D

Restarts the script

Q37

Q37 Which of the following control structures is unique to Perl?

A

do-while

B

foreach

C

given-when

D

switch-case

Q38

Q38 What will be the output of for (my $i = 0; $i < 3; $i++) { print "$i "; }?

A

1 2 3

B

0 1 2

C

0 1 2 3

D

Error

Q39

Q39 What does the following Perl code do?
while ($count < 5) { print "$count "; $count++; }

A

Prints 1 to 5

B

Prints 0 to 4

C

Prints 0 to 5

D

Throws an error

Q40

Q40 What will happen if a loop has a missing condition in Perl?

A

It runs infinitely

B

It throws an error

C

It executes once

D

It skips to the next loop

Q41

Q41 Why does this code if ($x = 5) { print "True"; } always print "True"?

A

The variable is uninitialized

B

The comparison is incorrect

C

The assignment operator is used instead of comparison

D

The loop is infinite

Q42

Q42 What is the effect of using next inside a loop in Perl?

A

Exits the loop

B

Skips the current iteration and moves to the next one

C

Throws an error

D

Repeats the iteration

Q43

Q43 What is the common cause of an infinite loop in Perl?

A

Using last inside the loop

B

Forgetting to increment a loop variable

C

Using redo incorrectly

D

Using next outside a loop

Q44

Q44 What keyword is used to define a subroutine in Perl?

A

sub

B

function

C

def

D

method

Q45

Q45 How does a Perl subroutine return a value?

A

Using return statement

B

Automatically returns the last evaluated expression

C

Both A and B

D

Perl subroutines do not return values

Q46

Q46 How are arguments passed to a subroutine in Perl?

A

Using parentheses

B

Through the special @_ array

C

Using the global variable $$args

D

Directly as individual variables

Q47

Q47 What does shift do inside a Perl subroutine?

A

Shifts the first value off an array

B

Moves the last value to the beginning

C

Removes all elements of an array

D

Adds a new value to an array

Q48

Q48 What is the default return value of a Perl subroutine if no explicit return is given?

A

0

B

undef

C

Empty string

D

The last evaluated expression

Q49

Q49 Which of the following is NOT true about Perl subroutines?

A

They can modify global variables

B

They can accept parameters

C

They always return a value

D

They are always executed in a new scope

Q50

Q50 What will be printed by this Perl subroutine?
sub greet { my $name = shift; print "Hello, $name!\n"; } greet("Alice");

A

Hello, Alice!

B

Hello, World!

C

Alice! Hello,

D

Syntax error

Q51

Q51 How do you call a Perl subroutine named calculate and pass two arguments (5,10)?

A

calculate 5, 10;

B

calculate(5, 10);

C

sub calculate(5,10);

D

call calculate 5, 10;

Q52

Q52 What will the following Perl subroutine return?
sub add { my ($a, $b) = @_; return $a + $b; } print add(2,3);

A

2

B

3

C

5

D

Error

Q53

Q53 A Perl subroutine is modifying a global variable unexpectedly. What is the likely cause?

A

The subroutine is modifying @_ directly

B

The variable was not declared with my

C

A return statement is missing

D

Perl subroutines cannot modify variables

Q54

Q54 Why does this subroutine throw an error?
sub example { my $x = shift; print "Value: $x"; } example();

A

$x is uninitialized

B

Too many arguments passed

C

Syntax error

D

Subroutines require return values

Q55

Q55 Why does this code not print anything?
sub test { return; print "Hello"; } test();

A

print is inside a return statement

B

Perl suppresses print inside subroutines

C

The function call is incorrect

D

Perl does not allow return values in subroutines

Q56

Q56 What operator is used in Perl for regular expressions?

A

==

B

=~

C

!=

D

<>

Q57

Q57 What does the ^ symbol mean in a Perl regular expression?

A

Matches the end of a string

B

Matches the beginning of a string

C

Matches a digit

D

Matches any character

Q58

Q58 What does /abc/i do in Perl regular expressions?

A

Matches "abc" exactly

B

Matches "abc" case-insensitively

C

Matches "abc" only at the start of a string

D

Matches "abc" only in arrays

Q59

Q59 Which character is used in Perl regex to match any single character?

A

*

B

.

C

+

D

?

Q60

Q60 What is the purpose of (?: ... ) in Perl regex?

A

Creates a capturing group

B

Creates a non-capturing group

C

Matches an empty string

D

Matches a single character

ad verticalad vertical
ad