Perl (Scripting) - return a string

by
Jeremy Canfield |
Updated: March 26 2021
| Perl (Scripting) articles
If you are not familiar with subroutines, check out our article on Perl - Getting Started with Subroutines.
Let's say you have the following script. In this example, the greeting subroutine will return string "Hello World".
sub greeting {
return "Hello World";
}
Outside of the subroutine, the output of the greeting subroutine is stored in the $foo variable.
my $foo = greeting();
You could then print the $foo variable.
print "$foo \n";
Which would return the following.
Hello World
Likewise, you could store the output of the greeting subroutine in an array.
Did you find this article helpful?
If so, consider buying me a coffee over at