use LWP::Simple;

# Download protein records corresponding to a list of GI numbers.

# nucleotide or protein database
$db = 'protein';
$id_list = '2026800804,2026800803,2026800802,2026800801,2026800800';

#assemble the epost URL
$base = 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/'; # basic URL to make all E-utility requests
$url = $base . "epost.fcgi?db=$db&id=$id_list";

#post the epost URL
$output = get($url);

#parse WebEnv and QueryKey
$web = $1 if ($output =~ /<WebEnv>(\S+)<\/WebEnv>/);
$key = $1 if ($output =~ /<QueryKey>(\d+)<\/QueryKey>/);

# get the sequences in FASTA
$url = $base . "efetch.fcgi?db=$db&query_key=$key&WebEnv=$web";
$url .= "&rettype=fasta&retmode=text";

$data = get($url);
print "$data";
