foreach my $line (@ids) { if ($line =~ /^(\w+\|\w+\.{0,1}\d{0,1}\|{0,1}:c{0,1}\d+\-\d+)/ +) { push @accessions, "$1"; }