seek $fh, $offset, SEEK_SET or die "$fn: D'Oh! $!\n"; read $fh, my $cont, $LEN; seek $fh, $offset, SEEK_SET or die "$fn: D'Oh! $!\n"; print $fh $cont ^ join '', map chr( rand 0x100 ), 1 .. $LEN; #### #!/usr/bin/perl use strict; use warnings; use Fcntl ':seek'; die "Usage: $0 file\n" unless @ARGV == 1; my $fn = shift; my $LEN = 3; open my $fh, '+<:raw', $fn or die "$fn: D'Oh! $!\n"; seek $fh, rand(-$LEN + -s $fh), SEEK_SET or die "$fn: D'Oh! $!\n"; print $fh map chr rand 0x100, 1 .. $LEN; __END__