$ cat spw759180_NetWallah #!/usr/bin/perl # use strict; use warnings; my @probs =(0,0.1,0.53,0.51,0.59,0.67,0.2,0.04,0.05,0.56,0.89,0.75,0.6); my $t; print $_ . (",","\n")[$t=1-$t] for grep {($probs[$_] >=.5 .. $probs[$_]> .5) and $t=!$t } 0..$#probs $ ./spw759180_NetWallah 2 4,9 11,$