in reply to Need writes to happen immediately.

$| controls application-level buffering. It ensures that perl will call write() with your data.

In general, the kernel is under no obligation to push this data to the underlying storage in anything like a timely fashion. You want fsync() for this job, which - as someone else points out - you can get to via syscall from perl.

If what you want is a sync after every write, then O_SYNC is pretty much that. You mention that this is very slow - so maybe check (with strace) that you are writing in the right-sized chunks, rather than character-at-a-time.