test.txt This is an example section. And the second line has structural science. jabb.mdb full | abb ------------- example | eg expand | exp section | sect science | sci test.out (required output) This is an eg sect. And the second line has structural sci. #### use Win32::ODBC; open( IN, '<', 'test.txt' ) or die "Couldn't open infile.\n$!"; open( OUT, '>', 'test.out' ) or die "Couldn't open outfile.\n$!"; $dsn = "test_dsn"; $db = new Win32::ODBC($dsn); die "ERROR: Failed to open database\n" if(!$db); $sql = "SELECT * from jabb"; $db->Sql($sql); while ($db->FetchRow()) { ($full, $abb) = $db->Data("full", "abb"); while(IN){ s!$full!$abb!g; print $_; print OUT $_; } close(OUT); } $db->Close();