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"; } }