my $text = ''; # put your complete works of Willie here my $separator = '|'; # and your separator here $text =~ s/[\^\n]([^\$\n]{25})/$1$separator/sg; print $text;