use strict; use warnings; use Fcntl qw( SEEK_SET ); . . . my @bytes; { my $input_location = 40; local $/=12; # Read 12 bytes open my $INF, '<', 'foo' or die; seek($INF, $input_location, SEEK_SET); my $t = <$INF>; @bytes = split //, $t; } # Do something with them @bytes = shuffle @bytes; # Write them to another file open my $OUF, '<+', 'bar' or die; my $output_location=1234; seek($OUF, $output_location, SEEK_SET); print $OUF, join("", @bytes);