I am iterating through a file and on each line I am looking for a regex. If the regex is found I just want to print "it's found" and then the index location of where it was found in that line.
Example:
looking for: 'HDWFLSFKD' need index between two Ds
line: MLTSHQKKF*HDWFLSFKD*SNNYNSKQNHSIKDIFNRFNHYIYNDLGIRTIA
output: 'its found' index location: 10-17
The above 'looking for' is quite simple but I am planning to have complex regex statements in there.
So basically Just want to know if a regex is found in a string then how do we get the index location of it?
Here is the code I have so far:
foreach my $line (@file_data)
{
if ($line=~ /HDWFLSFKD/){
print "it's found\n";
print "but at what index are the two Ds";
}
else {
$sequence.=$line;
print "came in else\n";
}
}