examples/subroutines/factorial.pl
#!/usr/bin/perl
use strict;
use warnings;

my $n = shift or die "Usage: $0 NUMBER\n";

my $result = factorial($n);
print $result;

sub factorial {
    my ($n) = @_;
    if ($n == 1) {
        return 1;
    }
    my $prev = factorial($n - 1);
    return $n * $prev;
}
examples/subroutines/fibonacci_recursive.pl
#!/usr/bin/perl
use strict;
use warnings;

sub fib {
    my $n = shift;

    if ($n == 1 or $n == 2) {
        return 1 
    }

    return (fib($n-1)+fib($n-2));            # recursive calling
}

print fib(10);                             # calling the function