use strict; use warnings; my $dir = '.'; for my $file (glob("$dir/*.seq")) { my $output = "$file.out"; open (my $in, '<', $file) or die "Unable to open $file: $!"; open (my $out, '>', $output) or die "Unable to open $output: $!"; while (<$in>) { s/\^\^/\n^^/g; print $out $_ } close ($in); close ($out); rename ($output, $file) or die "Unable to rename $output to $file:$!" }