in reply to Find a sequence in a multifasta files and motifs

Use a flip-flop to detect you're inside the correct sequence. Accumulate the sequence in a variable, use matching in scalarised list context to get the number of occurrences (the Goatse/Saturn operator). If the patterns can overlap, use a look-ahead instead of a plain match.
#! /usr/bin/perl use warnings; use strict; use feature qw{ say }; my $seq; while (<DATA>) { if (my $line_number = (/^>JJ22$/ ... /^>/)) { chomp; $seq .= $_ unless $line_number == 1 || $line_number =~ /E0/; } } my $count = () = $seq =~ /[MT].[KA]/g; say $count; __DATA__ >JJ57 MKIKLVTVGDAKEEYLIQGINEYLKRLNSYAKRETIEVPDEKAPEKLSDAEMLQVKEKEGEYVFVLAI NGKQLSSEEFSKEIFQTGISGKSNLTFTTCFSLGLSDSVLQRIMKGEPYHKL >JJ22 MDQNGASGSHPNRASTRKGAHARERGATVSAMSANRSNIIDEMAKICEADRQTFAIARRTRNESQ FFGFRTASNKAIEITEAMEKRGAMFLTQSKATDQLNGWQPSDEPDKTSAESEPWFRGKQLSSEEFS KEIFQTGISGKSNLTFTTCFSLGLSDSVLQRIMKGEPYHKL >JJ41 MWKTVAPIFAAIFAVGLCGTFRTNTRKGEPTTKCFVFVHDTKARIYQCTFKTWSCPWLNNIVSAQF QFVTGANYKIVVKLVGELFTETALFNWSSPTTIFTGLGTLITADKTLDCDSNML

The first check in the unless part excludes the header, the E0 is appended to the last line number, so it excludes the next header.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Find a sequence in a multifasta files and motifs
by rebkirl (Acolyte) on Jun 28, 2019 at 10:12 UTC
    Thanks...I'll try to fix the code