in reply to Square the array values.

To modify the input array, pass an array reference to the subroutine.
#!usr/bin/perl -w use strict; my @arr = qw( 1 2 3 4 5 6 7 8); square(\@arr); sub square { my $arrayref = shift; foreach my $item (@$arrayref) { $item **=2; #or #$item *=$item; } } foreach (@arr) { print "$_\n"; } __END__ prints: 1 4 9 16 25 36 49 64
This will produce the same @arr, but not quite in the same way:
my @arr = qw( 1 2 3 4 5 6 7 8); foreach (@arr) { $_*=$_; } #or @arr = map($_*$_}@arr;