It's close, although your code does not specify the mode to open the file with, and has the if condition outside the while loop, so won't work.
It's also better to use lexical file handles.
Untested modified code is below. I've also done some minor formatting changes, but avoided too many as it can become a matter of aesthetics.
my $fname = "file,fasta";
open my $fh, '<', $fname or die "Cannot open $fname, $!";
while (my $line = <$fh>) {
chomp $line;
if ($line =~ /CDECGKEFSQGAHLQTHQKVH/) {
print "The protein contains the domain";
}
else {
print "The protein doesn't contain the domain";
}
}
See also open and perlvar.