I have been coding in Perl without using "my" before the variable name.. when should I use MY and why?

my is a keyword for scope control. It also is required scope-wise for a perl program to pass strict and warnings.

use strict;
use warnings;

my $var="one";
print "$var\n";
{
	my $var="two";
	print "$var\n";
}
print "$var\n";

output:

one
two
one
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.