use strict; use warnings; my $infile = "rep_set_ass_tax.fna"; my $outfile = "seq_id.txt"; # you need to open this only if writing to a file open(IN, "<", $infile) or die "Died!!"; while (my $line=) { if($line=~/>\s*(\d+)/) { print $1 . "\n"; } } close IN;