use File::Format::RIFF; open( in, 'original.wav' ) or die "Could not open file: $!"; # This file has the "cart chunk" data I need. my ( $riff1 ) = File::Format::RIFF->read( \*in ); # Read the WAV into RIFF structure. close ( in ); $riff1->dump; # Dump info, just for reference. open ( middle, 'target.wav') or die "Could not open file: $!"; # This is an MP2-encoded wav. # The idea is to get the "cart chunk" from $riff1 and add it to $riff2, then overwrite target file. my ( $riff2 ) = File::Format::RIFF->read ( \*middle ); # read target file in to RIFF container close ( middle ); foreach my $chunk ( $riff1->data ) # step thru original wav, skipping all but "Cart" chunk { if ( $chunk->id eq 'cart' ) { $riff2->addChunk( $chunk->id, $chunk->data); # Add cart chunk from $riff1 to $riff2 } } open(out, '>target.wav') or die "Couldn't open file: $!"; # overwrite mp2 file with "chunked" data $riff2->write( \*out ); close( out );