PERL technical interview questions and answers are useful for candidates applying for scripting, automation, and system administration roles. PERL is widely used in text processing, network programming, automation scripts, and backend development, making it a common interview topic in IT companies. Recruiters from TCS, Wipro, Infosys, Cognizant, Capgemini, and Accenture often test candidates on PERL basics, syntax, regular expressions, arrays, hashes, file handling, subroutines, and modules. This guide provides clear explanations and examples for the most important PERL interview questions. Whether you are preparing for campus placements or experienced-level interviews, this resource will help you strengthen your scripting knowledge. You can also download PERL interview PDFs and practice mock questions to improve your performance.
Showing 10 of 25 questions
11. Why is it hard to call this function: sub y { "because" }
Because y is a kind of quoting operator.
The y/// operator is the sed-savvy synonym for tr///. That means y(3) would be like tr(), which would be looking for a second string, as in tr/a-z/A-Z/, tr(a-z)(A-Z), or tr[a-z][A-Z].
12. What does read() return at end of file?
A defined (but false) 0 value is the proper indication of the end of file for read() and sysread().
13.
What does `new $cur->{LINK}' do? (Assume the current package has no new() function of its own.)
$cur->new()->{LINK}
The indirect object syntax only has a single token lookahead. That means if new() is a method, it only grabs the very next token, not the entire following expression.
This is why `new $obj[23] arg' does't work, as well as why `print $fh[23] "stuff\n"' does't work. Mixing notations between the OO and IO notations is perilous. If you always use arrow syntax for method calls, and nothing else, you'll not be surprised.
14. How do you find the length of an array?
$@array
15. What value is returned by a lone `return;' statement?
The undefined value in scalar context, and the empty list value () in list context.
This way functions that wish to return failure can just use a simple return without worrying about the context in which they were called.
16. What's the difference between /^Foo/s and /^Foo/?
The second would match Foo other than at the start of the record if $* were set.
The deprecated $* flag does double duty, filling the roles of both /s and /m. By using /s, you suppress any settings of that spooky variable, and force your carets and dollars to match only at the ends of the string and not at ends of line as well -- just as they would if $* weren't set at all.
17. How to dereference a reference?
There are a number of ways to dereference a reference.
Using two dollar signs to dereference a scalar.
$original = $$strref;
Using @ sign to dereference an array.
@list = @$arrayref;
Similar for hashes
18. What does length(%HASH) produce if you have thirty-seven random keys in a newly created hash?
length() is a built-in prototyped as sub length($), and a scalar prototype silently changes aggregates into radically different forms. The scalar sense of a hash is false (0) if it's empty, otherwise it's a string representing the fullness of the buckets, like "18/32" or "39/64". The length of that string is likely to be 5. Likewise, `length(@a)' would be 2 if there were 37 elements in @a.
19. If EXPR is an arbitrary expression, what is the difference between $Foo::{EXPR} and *{"Foo::".EXPR}?
The second is disallowed under `use strict "refs"'.
Dereferencing a string with *{"STR"} is disallowed under the refs stricture, although *{STR} would not be. This is similar in spirit to the way ${"STR"} is always the symbol table variable, while ${STR} may be the lexical variable. If it's not a bareword, you're playing with the symbol table in a particular dynamic fashion.
20. How do I do < fill-in-the-blank > for each element in an array?
#!/usr/bin/perl -w
@homeRunHitters = ('McGwire', 'Sosa', 'Maris', 'Ruth');
foreach (@homeRunHitters) {
print "$_ hit a lot of home runs in one year\n";
}