use warnings; use strict; use Switch; my $dna = 'atctcttttcgtctgctttggggtttgtcctataggcta'; my $base = ''; my @bases = (); my $a = ''; my $c = ''; my $g = ''; my $t = ''; my $err = 0; my $total = 0; calc_base( $dna ); sub calc_base { my ( $dna ) = @_; print 'Please enter a base to calculate: '; chomp( $base = ); @bases = split '', $dna; $total = length $dna; for( @bases ) { ++$a if /a/; ++$c if /c/; ++$g if /g/; ++$t if /t/; ++$err if /[^acgt]/; } switch ( $base ) { case "a" { printf "The amount of adenosine in the sequence is %.2f%%", ( ($a/$total) * 100); } case "c" { printf "The amount of cytosine in the sequence is %.2f%%", ( ($c/$total) * 100); } case "g" { printf "The amount of guanine in the sequence is %.2f%%", ( ($g/$total) * 100); } case "t" { printf "The amount of thymidine in the sequence is %.2f%%", ( ($t/$total) * 100); } } }