$id = $Words_db{$word}; foreach $i (keys %Index_db) { if ($i == $id) { @fileId = split( /:/, $Index_db{$i}); foreach $fId (@fileId) { # ... } } }