in reply to Unexpected value of $_ in a for loop.

$_ is not used in the loop. @_ and $#_ (last index of @_) actually refer to the parameters passed into the sub.

Here's a more efficient shuffling algorithm, especially on large arrays:
use strict; use warnings; use Data::Dumper; my @cards = qw/ A 2 3 4 5 6 7 8 9 10 J Q K /; @cards = shuffle_Deck(@cards); print Dumper(\@cards); sub shuffle_Deck { my @new = (); for (@_) { my $i = int rand($#new+1); push @new, $new[$i]; $new[$i] = $_; }; return(@new); }