About filling up your array... you're using a random index number and will only stop if there are 5 different indexes, possibly looping more than 5 times.
I find the following much more clean: It only loops 5 times, for sure:
my @list = ();
foreach my $i (1..5) {
push @list, int(rand(50)+1);
}