#!/usr/bin/perl -w use strict; # Store the formats in variables (you don't have to use here-docs) my $header = << 'HEADER'; Menge Art.nr. Bezeichnung Preis($) Gesamt($) _____________________________________________________________________ HEADER my $body = << 'INHALT'; @<<<< ^<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>> @>>>>>>>>> INHALT my $continue = << 'INHALT2'; ^<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<< INHALT2 my $footer = << 'FOOTER'; _____________________________________________________________________ Warenwert: @>>>>>>>>> FOOTER # Sample data my @bestellung = ('Long ID number|123456789012345|3.99|7', 'Text two, this is a long line|2|5.49|8', 'Text three, this is the longest line|3|7.89|9'); formline($header); foreach (@bestellung) { my ($text, $nr, $preis, $menge) = split /\|/; my $summe = sprintf("%.2f", $menge*$preis); formline($body, $menge,$nr,$text,$preis,$summe); while (length $nr or length $text) { formline($continue, $nr,$text); } } formline($footer, 1234); print $^A; # Print the accumulator $^A = ''; # Clear the accumulator __END__ Prints: Menge Art.nr. Bezeichnung Preis($) Gesamt($) _____________________________________________________________________ 7 123456789 Long ID number 3.99 27.93 012345 8 2 Text two, this is a long 5.49 43.92 line 9 3 Text three, this is the 7.89 71.01 longest line _____________________________________________________________________ Warenwert: 1234