#/usr/bin/perl @ARGV = ('test.txt'); open FILE, $ARGV[0] or die "can't open file\n"; $string = ''; @file = ; foreach $line(@file){ if ($line =~ /^>/){next;} else {$string .= $line;} } #the first line is useless so need to skip in close FILE; my $search = 'TTGACA'; $string =~ s/\s//g; #getting rid of whitespaces $n = ($string =~ tr/$search//); print "String $search occured $n times\n\n";