+------------------+ | This is my menu | +------------------+ | | +------------------+ #### menuAdd('A really long string that I want to add to the awesome menu system',20); #### +------------------+ | This is my menu | +------------------+ | | | A really long st | | ring that I want | | to add to the aw | | esome menu syste | | m | +------------------+ #### +------------------+ | This is my menu | +------------------+ | | | A really long | | string that I | | want to add to | | the awesome menu | | system | +------------------+ #### sub menuAdd{ my $text = shift; my $menuWidth = shift; my $textLength = length($text); $menuWidth-=4; #shorten $menuWidth to leave room for | and a space on left and right sides of the menu if ( $textLength <= $menuWidth ){ #add spaces to end of $text to maintain menuWidth print "| " . padSpaces($text,$menuWidth) . " |\n"; } elsif( $textLength > $menuWidth ){ #split $text into separate lines to maintain menuWidth my @textArray = split(/(.{$menuWidth})/, $text); print @textArray; foreach my $line (@textArray){ print "| " . padSpaces($line,$menuWidth) . " |\n"; #print "| $line |\n"; } } else { print "******SHOULD NEVER GET HERE******\n"; } }