use strict; use warnings; sub get_max_index { my (@copyOfArray) = @_; #make an explicit local copy my $imax= shift @copyOfArray; # modifies this copy, but ok for (@copyOfArray){ # no indices... $imax = $_ if $imax < $_; } return $imax; } my @arr = (1..10); my $ans = get_max_index(@arr); print"$ans\n";