my $total = 0; my $expect = 0; for(int i=0;i<@array;i++) { $total += $array[$i]; $expect += $i; Correction: $expect += $i + 1; } return 1 if ($total == $expect);