$Agent1=$dbh->prepare('select substring_index(substring_index(substring_index(Name,"$$$",1),"$$",1),"\$",-1) as Phone_no, substring_index(substring_index(Name,"$$$",1),"$$",-1) as Mail_Id from CustomFieldValues where CustomField =291 and Name like "$name%";') || die "$DBI::errstr"; $Agent1->execute() || die "$DBI::errstr" ; ( $phone_no,$mail )= $Agent1->fetchrow_array; print "Phone:\t$phone,Mail:\t$mail\n";