The presented code works fine for me using ActivePerl 5.6.0, 5.6.1, 5.8.0, 5.8.8, 5.8.9 and 5.10.0 on WinXP. Could it be that a pipe fills up when the actual program is used?
The dir command works fine for me until I chdir to a larger directory, at which point dir never completes because it blocks writing to the full pipe attached to STDOUT. Just like I predicted.