#!/usr/bin/env perl -l use strict; use warnings; my @data = ( [1,1,,,,], [1,2,,,,], [3,4,1,1,,], [1,1,1,1,,], [5,6,3,4,1,2], [1,1,,,,], [1,1,1,1,1,1], [2,3], [1,1,1,2], [], [3,2,1], ); my %lines_with = (success => 0, fail => 0); for my $line (@data) { my ($success, $fail) = (0, 0); while (@$line) { my ($first, $second) = splice @$line, 0, 2; next unless defined $first && $first == 1; next unless defined $second; ++$success if $second == 1; ++$fail if $second == 2; } ++$lines_with{success} if $success; ++$lines_with{fail} if $fail; } print "Lines with successes: $lines_with{success}"; print "Lines with fails: $lines_with{fail}"; #### Lines with successes: 6 Lines with fails: 3