OK now we know a bit more, here are a couple of thoughts - repeatedly manipulating such data in Perl even for interfacing will be slow. There are C macros (see perlguts) for managing data declared in Perl and passed by reference (C-style, not Perl-style). But I'd aim to get it into C static storage (scope it just outside your C routines) asap and leave it there (call C routines from Perl at every point it needs using in any way), preferably loading it directly into C in the first place and avoid reallocating C memory repeatedly i.e. when completely done with one 1Mb chunk, reuse the same static storage for successive such chunks to process. Don't use the SV char* type -- use e.g. static int fred*250000 (update: unsigned) (scoped before the C routines are declared but after __C__) for your C storage to avoid ASCII-zero truncation by libc whenever a null byte is encountered.