How do I select a random element from an array?

Use the rand function (see rand):

    srand;			# not needed for 5.004 and later
    $index   = rand @array;
    $element = $array[$index];

If you just want a random line from a file, you can do this:

    srand;
    rand($.) < 1 && ($line = $_) while <>;

This has a significant advantage in space over reading the whole file in.