my $file = '/path/to/file'; my $line_start = 'BB'; my $search = 'wort3'; open my $fh,'<',$file or die $!; while(my $line = <$fh>){ next unless $line =~ /^\Q$line_start\E/; print "yes\n" if $line =~ /\Q$search\E/; } close $fh;