#! /usr/bin/perl -w
use strict;

#### Main part of the program
my @fasta = <>; 

my $hashref = SearchFasta(\@fasta, ['TAA', 'TATA', 'GCA', 'GCG', 'GGG']);

foreach my $key ( sort keys %{$hashref} ) {
    print "$key: $hashref->{$key}\n";
}

sub SearchFasta {
    
    # Get the references from the argument array
    my ($f1ref, $subsref) = @_;
    
    # Dereference
    my @f1 = @{$f1ref}; # This makes a copy of the referenced array
    
    # Make a long string of the fasta sequence
    my $seq = join '', @f1;
    
    # Remove all comment lines
    $seq =~ s/>.*?\n//g;
    
    # Remove all new lines
    $seq =~ s/\n//g;

    # Loop over all substrings to search for
    my %cnt;
    foreach my $sub ( @{$subsref} ) {
	$cnt{$sub} = ($seq =~ s/$sub/$sub/g); 
    }
    
    # Return the hash of matches
    return \%cnt;
} 
