might observe different behavior if it’s running to a terminal. I don’t know if perl uses stdio, but that varies:
The stream stderr is unbuffered. The stream stdout is line-buffered when it points to a terminal. Partial lines will not appear until fflush (3) or exit (3) is called, or a newline is printed. This can produce unexpected results, especially with debugging output.
When opened, the standard error stream is not fully buffered; the standard input and output streams are fully buffered if and only if the streams do not refer to an interactive device.
Be careful with output. See Where does script output go to (difference between BEFORE and AFTER?)