open(INPUT,"filename.txt") or die "Will not open input: $!"; open(OUTPUT,">output.txt"); or die "Will not open output: $!"; my $input = ; my $line; my $i; my $length = length($input); for ($i=0; $i<$length; $i=$i+164){ $line = substr($input,$i,164); print "$line\n"; #Output to screen to make sure it works print OUTPUT "$line\n"; }