print "Connecting to database... "; #this print works # Connect to the SQL database my $dbh = DBI->connect($dsn,'username','password',{RaiseError=>0, PrintError=>0}); if ($dbh) { print "Connected.\n"; #gets printed }else{ print "Cannot connect to database. (",$dsn,")\nQuitting\n"; exit; } print "Processing File... "; # delayed till near end. my $sth = $dbh->prepare( qq{ SELECT field1 FROM Table WHERE field2 = ?}); open(FILE, 'data'); # gonna process a BIG file while() { $sth->execute($_); # etc etc... } close FILE; print "Done processsing file\n";