use strict; use warnings; my $filename = 'fasta.txt'; open my $FILE, '<', $filename or die "Could not open $filename: $!"; while(my $line = <$FILE>) { if($line=~/^>.*unknown/ ) { $line .= ; print $line; } } close $FILE; #### test not this > unknown print this no no no again > known (not this header) got you! no way Jose > HEADER unknown Yessir! not this line throw this away #### > unknown print this > HEADER unknown Yessir!