Problem with my split routine I am not understanding



I have the following function:

subroutine split(what, by, into)
implicit none

character(len=*), intent(in) :: what, by
character(len=*), dimension(:), intent(out) :: into

integer :: bpos = 1, pos = 1, idx = 1

do
pos = scan(what(bpos:), by)
if (pos == 0) exit
into(idx) = what(bpos:pos + bpos - 2)
idx = idx + 1
bpos = bpos + pos
end do

into(idx) = what(bpos:)

end subroutine split

To test this, I have:

program SplitTest
uses splitmod
implicit none

character(10), dimension(1:2) :: data

call split('JOHN|DOE', '|', data)
print *, data(1) ! outputs: JOHN

call split('JANE|SMITH', '|', data)
print *, data(1) ! outputs: JANE
end program SplitTest

The problem is that once the array data is filled, it seems to not change.
Any ideas on what I am doing wrong?

Jeremy
.