A loop is not inefficient. See my reply to this thread for an efficient way of minimizing disk I/O.