A subroutine is like a function ... called upon to excecute a task.
When we are defining a function we have to use sub keyword in front of function name.<br><br>syntax:<br> sub functionname<br> {<br> statement;<br> }<br>Example:<br> if($a>0)<br> {<br> &fun();<br> }<br> sub fun<br> {<br> print "hai";<br> }
Subroutine is perl is a block of code specially combined/grouped to perform a particular task.Which can e called at any point of time in a perl program.<br><br>Advantage using Subroutine<br> a) helps in modular programming making it easier to understand and maintain<br> b)eliminates duplication by reusing the same code/calling the subroutine.