my $lines_per_page = 50; # print 50 lines per page my $y_init = 600; # initial top line pos my ( @pages, $page, $y ); # declare and scope these vars foreach my $line ( 0 .. $#textstrings ) { # get line from array using index my $text = $textstrings[$line]; # remove all control characters using tr with /d(elete) # option. these are specified in octal notation $text =~ tr/\000-\037//d; # we will have removed the traling newline from each line. # I doubt that it is required but if it is... $text .= "\n"; # use modulus operator % to make a new page whenever # the current line number divided by the lines per # page has a remainder of zero. this will get us a new # $page object when $line == 0, 50, 100 ... # we push each completed page into the @pages array if ( $line % $lines_per_page == 0 ) { push @pages, $page; $page = $root->newpage; $y = $y_init; # reset the $y value to page top } # add the text to the current page $page->string( $f1, 10, 20, $y, $text ); # move y position down 10 pixels $y = $y - 10; } # now summate the pages in @pages (if that's what you need) $page = join'', @pages;