🐪 Perl Subroutines
Subroutines (aka subs) in Perl are reusable code blocks you can call by name — making your code cleaner and DRYer.
🖥️ Example 1: Basic Subroutine
Define with sub
and call it by name.
Output will appear here...
🖥️ Example 2: Subroutine with Parameters
Use @_
inside the sub to access arguments.
Output will appear here...
🖥️ Example 3: Subroutine Returning a Value
Use return
to send a result back to the caller.
Output will appear here...
💡 Tip: In Perl, subroutine parameters are automatically stored in the @_
array.