sub countrows { # First parameter is a pointer/reference to the data # Second parameter is an array of columns numbers my ($data,@f)= @_; my $count=0; foreach my $row (@$data) { my $success=1; foreach (@f) { if ($row->[$_] ne 'z') { $success=0; last; } } $count+= $success; } return $count; } my @data= ( ['z',4,'z',4,'z'],['z',4,'z',4,4],['z','z','z',4,'z'] ); print countrows(\@data,0,2),' ',countrows(\@data,1,3,2),' ',countrows(\@data,4),"\n"; # print 3 0 2 #### sub randomarray { my ($columns,$count)= @_; my @all; push @all, $_ foreach (0..($columns-1)); my @randarray; while ($count-- >0) { push @randarray, splice(@all, int(rand(@all)),1); } return @randarray; } print join ' ',randomarray( scalar @{$data[0]} , 2 ),"\n"; print join ' ',randomarray( scalar @{$data[0]} , 3 ),"\n"; print join ' ',randomarray( scalar @{$data[0]} , 4 ),"\n"; # might print 3 4 3 0 1 0 1 4 2