All the arguments passed to a perl subroutine are packed in an array “@_”. The following script shows you how to access function arguments in a subroutine.

[nick@techpulp ~]# cat funargs.pl
#!/usr/bin/perl

sub myfun
{
  my $i = 0;
  $nargs = $#_+1;
  print "Number of arguments: $nargs\n";
  foreach $arg (@_) {
    $i++;
    print "Arg $i: $arg\n";
  }
}

myfun("One", "Two");
[nick@techpulp ~]#

Let us run the above script.

[nick@techpulp ~]# ./funargs.pl
Number of arguments: 2
Arg 1: One
Arg 2: Two
[nick@techpulp ~]#

If the subroutine is expected to take fixed number of arguments, you can simplify the script as following.

[nick@techpulp ~]# cat funargs.pl
#!/usr/bin/perl

sub myfun
{
my ($arg1, $arg2) = @_;
print "Arg 1: $arg1\n";
print "Arg 2: $arg2\n";
}

myfun("One", "Two");
[nick@techpulp ~]#

The output of of above script is:

[nick@techpulp ~]# ./funargs.pl
Arg 1: One
Arg 2: Two
[nick@techpulp ~]#