# declare your hash my %hGoIds; # read in the file using XML::Twig or line by line # if you must. Now for each number you find: $hGoIds{$go_id} = 1; # when you have read in all of the lines and found all of # the numbers, extract your keys my @aKeys = keys %hGoIds;