%database_index; # Run me once my $idx=0; for (@database) { $database_index{$_} = $idx++; } # /Run me once # good candidate for a BEGIN block - caveat dynamic # This is pretty standard and not best for all situations