open( IN, "big.file" ) or die $!; while ( read( IN, my $cleartxt, 8192 ) > 0 ) { my $cryptxt = ""; while ( $cleartxt ) { $tocrypt = substr( $cleartxt, 0, 16 ); $cleartxt = substr( $cleartxt, 16 ); if ( length( $tocrypt ) != 16 ) { $tocrypt .= " " x ( 16 - length( $tocrypt )); } # do what you need with Twofish to encrypt, and # append result to $cryptxt } print $cryptxt; }