Improved substring using scan