the scanning perl program gen.pl: --------------------------------- #!/usr/bin/perl use strict; my @array = qw(13470319 13470331 15460001 13490216); my @array2; while(my $line = <> ) { foreach my $id (0..$#array) { $array2[$id]=$line if $line =~ m/^gi\|($array[$id])\|/; } } print "order: ", join (" ", @array), "\n"; map {print} @array2; ------------------------------- the text file: gi|13470331|ref|NP_101896.1| hypothetical protein MFWVTKKALMPFLMLPAGIIFVSAVGYAINWLFSTLFQFQPPLVEGPAGPVTVLIFTITMLLAYDISYYL gi|13470319|ref|NP_101897.1| hypothetical protein MGAYCQAHPACKVTDRTVIGRRDAAMNAPFVLAIPRTRTFEVVTSAARLAEIAPAWTALWQRAGGLVFQH ------------------------------- the execution: # cat gen.txt | perl gen.pl order: 13470319 13470331 15460001 13490216 gi|13470319|ref|NP_101897.1| hypothetical protein gi|13470331|ref|NP_101896.1| hypothetical protein