To force the matching to the end of the string, write a dollar sign $ as the last character of the regular expression.
Now let us see how to do that using a regular expression matching (though it is less efficient in this case).
To print the "description" line, which starts with DE, we write:
#!/usr/local/bin/perl
my $sp_file = "sources/sp_entry";
open (SP, $sp_file) || die "cannot open \"$sp_file\": $!";
while (my $line = <SP>) {
if ($line =~ /^DE/) {
print $line;
}
}
Result:
DE MUSCARINIC ACETYLCHOLINE RECEPTOR M1.Note: if we omitted the caret from the regular expression:
if ($line =~ /DE/)We would have got:
DE MUSCARINIC ACETYLCHOLINE RECEPTOR M1.
RA ARDEN J.R., NAGATA O., SHOCKLEY M.S., PHILIP M., LAMEH J., SADEE W.;
CC CELLULAR RESPONSES, INCLUDING INHIBITION OF ADENYLATE CYCLASE,
CC BREAKDOWN OF PHOSPHOINOSITIDES & MODULATION OF POTASSIUM CHANNELS
SERSQPGAEG SPETPPGRCC RCCRAPRLLQ AYSWKEEEEE DEGSMESLTS SEGEEPGSEV
if ($file =~ /\.pl$/) { }
# Note: there is a backslash before the dot, since we mean a literal
# dot and not "any character except newline" (see here).