my $pattern = 'C1, 2(11)'; while () { next if not /$pattern/; # do something with the line if it has $pattern } #### next if not /^$pattern/;