$amount_of_keys = keys %upload; # for all instances of $amount_of_keys % 20 { # print qq(); } } #### keys 1-20 would print url1.html keys 21-40 would print url2.html keys 41-60 would print url3.html keys 61-80 would print url4.html (even though we don't have 80 images, we have a surplus and still need to generate a url for it).