This line
for (my $num = $members) {
raises a flag. I would expect to see something like
for my $num ( @members ) {
or, if members is a reference to an array,
for my $num ( @$members ) {
Instead, what's there is basically a one-trip loop, which leads me to suspect that this isn't what you intended.