I think my problem might have been that I was reading my input from unix standardin. When I put the data in a file, it works fine
I can research later why my problem was happening, but for now I can at least parse the data I'm working with by piping it to a file first and opening it in perl.