#!/usr/bin/perl
use strict;
use warnings;

# initializing variables
my ($dna_seq,$A,$C,$G,$T,$N);

$dna_seq  = "ATGCATTGGGGAACCCTGTGCGGATTCTTGTGGCTTTGGCCCTATCTTTTCTATGTCCAAGCTG".
            "TGCCCATCCAAAAAGTCCAAGATGACACCAAAACCCTCATCAAGACAATTGTCACCAGGATCAA";

$A = $C = $G = $T = $N = 0;

# Looping throught the sequence
my $seqlen = length($dna_seq);

for (my $i = 0; $i < $seqlen; $i++) {

    my $char;

    $char = uc(substr($dna_seq,$i,1));

    SWITCH: {
		$char eq 'A' && ($A++, last SWITCH);
		$char eq 'C' && ($C++, last SWITCH);
		$char eq 'G' && ($G++, last SWITCH);
		$char eq 'T' && ($T++, last SWITCH);
		$N++; # default value when char not found in {A,C,G,T}
	};

};

# Printing results
print STDOUT "Total A = $A\n";
print STDOUT "Total C = $C\n";
print STDOUT "Total G = $G\n";
print STDOUT "Total T = $T\n";
print STDOUT "Total N = $N\n" if $N > 0;
