while(my $char = getc(IN)) { if($kp >= length($key)) { $kp = 0; } my $kc = substr($key, $kp++, 0); $char ^= $kc; print OUT $char; }