Flex provides a mechanism for creating and switching between multiple input buffers. An input buffer is created by using: yy_creat_buffer and gives the possibility to switch input stream by using yy_switch_buffer.
The problem is lex does not implement a solution like that.
you can find more in the Flex manual