use strict; use warnings; local $/ = 'Frame: '; while (<>) { next unless my ($frame) = /(\d+)/; my $count = grep /C/, split /\n/; print "Frame: $frame " . $count . "\n"; }