#!/usr/bin/perl use strict; use warnings; use diagnostics; unless (open (INFILE, "<", "/scratch/SampleDataFiles/test.fasta")){ die "Unable to open file", $!; } local $/ = ">"; #find and print desired sequence while () { chomp; #always chomp if ( $_ =~ /^(.*?)$(.*)$/ms ) { #match first line as header my $header = $1; #assign the parts of the match my $seq = $2; $seq =~ s/\n//g; #get rid of whitespace while($seq =~ /([VILMFWCA]{8,})/g){ #search for desired sequence my $location = pos($seq); #find location my $length = length($1); #determine length print "Hydrophobic stretch found in: ", $header, "\n"; #printing outputs for results print $1, "\n"; print "The match was at position: ", $location - $length + 1, "\n\n"; } } } close INFILE;