in reply to Selecting a random number, and back calculating to chromosome and contig!

I am also seeing the following, which to me looks like a copy/paste error, where the my is inadvertently included, and the quotes are omitted:

print "Chromosome $chromosome, contig my $contig\n";
I also cannot agree more with thor, who has given you an excellent suggestion on refactoring that code.