Variable Scope

Let's discuss the scope of variables in Perl.


The scope of a variable refers to the variable’s visibility, i.e. which part of the program can access that variable.

Types of variables

There are two types of variables depending on the scope (or visibility):

  • Local variables
  • Global variables

Local variables

Variables defined within the body of a function or subroutine using the my keyword are called local variables. A local variable cannot be accessed outside of its respective subroutine.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy