#!/usr/bin/perl -wT use strict; while() { chomp; if( m{^(\s+)(?:print\s\"(.*)\"\;)$}g ) { splittor($1,$2); next; } print $_."\n"; } exit; sub splittor { my $indent = shift || ''; my $str = shift; # quick hack for accurate count my $tabcount=0; $tabcount++ for ($indent =~ /\t/g); # assuming tab == 4 spaces my $maxlength = 60-length($indent)-($tabcount*3); my ( @str ) = grep $_, split /(.{1,$maxlength})/, $str; print "${indent}print "; print join ( ",\n$indent\t", map {'"'.$_.'"'} @str ); print ';'."\n"; return undef; }