use strict; use warnings; my $original = &promptUser("Enter original filename"); my $modified = &promptUser("Enter modified filename"); open(my $ORIG, "$original") or die "could not open $original"; binmode($ORIG); open(my $MOD, ">$modified") or die "could not open $modified"; binmode($MOD); # commented out $/ = "\x00"; while (<$ORIG>) { my $count = ((my $change = $_) =~ s/(\x33\x33\x39\x39.*?\x00)/"\x00" x length($1)/e); if ($count == 0) { print $MOD $_; } else { my $answer = &promptUser("Modify $1?"); if ($answer eq "y") # <-- eq for test, == is for numerical comparisons { print $MOD $change; } else { print $MOD $_; } } } close $MOD; close $ORIG; sub promptUser { my($promptString, $defaultValue) = @_; if ($defaultValue) { print $promptString, "[", $defaultValue, "]: "; } else { print $promptString, ": "; } $| = 1; # force a flush after print my $line = ; # get the input from STDIN chomp($line); if ($defaultValue) { return $line ? $line : $defaultValue; } # return $line if it has a value else { return $line; } }