<disclaimer>Code untested</disclaimer>
Quick list of things that hit me:
- Are you sure you want local($promptString,$defaultValue) instead of my ($promptString,$defaultValue) ?
- $| needs to be either localized (best) or turned on and off immediately around the print in question. How it is used now is equivalent to putting $| = 1; at the top of your posted code segment.
- Ideally, the three argument form of open leaves less ambiguity.
As your record separator is set to the same thing you are s///ing for, why not use chomp and be done with it? I rethought this one, my idea would not work.
- I know advocating a One True Brace Style will spark a holy war. But as it stands, it is difficult to tell at a glance what is inside what block.
- Have you split $count = (($change = $_) =~ s/(\x33\x33\x39\x39.*?\x00)/"\x00" x length($1)/e); up into its constituent parts to verify it's doing what you want?
- Have you injected print STDERR $somevar at strategic locations in your code? You've stated that it fails after the first y user input. This would answer how far after the user input it fails (which could give some important clues).