in reply to get some part of the string using regex


The problem is that your regex is "greedy": it is matching as far ahead as possible. A negated character class in the regex is one way of dealing with this:
#!usr/bin/perl -w use strict; my @lines = qw( >sp|P49929|SC52_SHEEP DITCAEPQSVRGLRRLGRKIAHGVKKYG >gi|1771590|emb|CAA70562.1| temporin B precursor ); foreach (@lines) { if (/^>(\w+)\|([^|]+)/){ print "$1 == $2\n"; } } __END__ Prints: sp == P49929 gi == 1771590

Also, if the second field only contains word charcters you could use a simpler match:     /^>(\w+)\|(\w+)/

--
John.