sub reverse_inplace { for ( my $i = 0; $i < $#_ / 2; $i++ ) { my $j = $#_ - $i; @_[$i,$j] = @_[$j,$i]; # swap } } # try it: my @a = ( 1 .. 9 ); reverse_inplace( @a ); print "@a\n";