I have a SD file to read. I couldn’t upload the whole file. so I gave a snapshot in the image below.

This is a SD file (Structural data file) that explains the structure of a molecule. 803 and AMH are two molecules. Also, within same molecule there are several fragments. Each fragment is separated by four dollar sign ($$$$). I am a new to perl as I am a biomedical research student. However, I wrote a script that finds the occurrence of $$$$ and then the occurrence of molecule code (here 803) in line next to it.
{
open (FILE, '<', "try_803.txt");
my $ligandcode="803";
while (<FILE>) {
my $nextline = <FILE>;
if ( $_=~/\x24\x24\x24\x24/ && $nextline=~/$ligandcode/){
# do something
}
}
}
This code checks the very first occurrence of $$$$ followed by 803. But, I want it to go further to next occurrence of $$$$ followed by 803. I don’t know how many times will this pattern will occur. technically I can’t specify the no of fragment before hand. Can you help me improving this code and finding a solution for problem. I’ll be grateful.
You can set the input record separator to four dolar signs, a newline and 803.
Then, you can read the whole molecules in a loop: