my @usernames = qw(zero one two three four five six); testswap(\@usernames); print join(" ", @usernames), "\n"; sub testswap { my $array = shift; my $i = 2; my $j = 5; @$array[$i, $j] = @$array[$j, $i]; } #### zero one five three four two six #### my $username = $usernames[rand(@usernames)];