I agree with holli, you would find it easier to use Perl. However, you say that sqlplus 'hangs', and it would be good to find out the reason. When you run sqlplus from the command line under these conditions, what happens? Do you have truss(1) or strace(1) available to see why it has stopped?