What’s the difference between single and double quotes in Perl?

Double quotes use variable expansion. Single quotes don’t

In a double quoted string you need to escape certain characters to stop them being interpreted differently. In a single quoted string you don’t (except for a backslash if it is the final character in the string)

my $var1 = 'Hello';

my $var2 = "$var1";
my $var3 = '$var1';

print $var2;
print "\n";
print $var3;
print "\n";

This will output

Hello
$var1

Perl Monks has a pretty good explanation of this here

Leave a Comment