local $_; # should always do this unless you know why you don't want it my %id_cache; open (IMAGE_LIST, $image_list); # you didn't need quotes here.. while() { $id_cache{substr($_,1)} = substr($_,0,1) eq 'Y'; } close (IMAGE_LIST); open (IMAGE_LIST, ">>$image_list"); # although you do here for (@thumb_id_list) { unless(exists $id_cache[$_]) { # IDs that didn't appear in the file won't exist in the hash # therefor we have to connect to partner website for them $id_cache[$_] = &check_image($session,$_); print IMAGE_LIST $id_cache[$_] ? "Y$_\n" : "N$_\n"; } # $id_cache[$_] is now defined, # regardless of whether it was in the file or not push (@display_thumbs,$_) if $id_cache[$_]; } close (IMAGE_LIST);