#!/usr/bin/perl -w use strict; open DATA , "; my $count_A = 0 ; close DATA ; foreach my $line (@output) { my $length = length ($line); if (substr($line, 0,$length) eq 'A') { $count_A++; } print $count_A++;