sub split_long
{
 # Declare our variables as local to this subroutine:
 my ($value,$newvals,$offset,$length,$tmp,$tmp2,$last,@words);
 
 $value = shift;				# Get the data to split long words in.
 $newvals = '';					# Initialise $newvals as blank.
 @words = split(/\s+/,$value);	# Split the data into an array of individual words.
 
 
	# Loop over each word from the array of words and do the following:
 
	# 1. If the word is longer than the maximum allowable length defined:
	# 	a. Get the length of the word ($length).
	# 	b. Set the initial offset to 0.
 
	# 	c. While the offset + the max length is less than or equal to $length:
	#	i.   Get a substring (partial string) from $word, from the offset to the max length.
	#	ii.  Append this substring to $newvals with a trailing "-" and HTML line break "<br>".
	#	iii. Increase the offset by the value of the maximum allowable length.
 
	#	d. If we're still not at the end of the string, get the last substring.
 
	# 2. If the word is within the maximum allowable length, just appent it to $newvals.
	# 3. Now we just return the string with the long words split up as neccessary.
 
 foreach my $word (@words){
  if ( length($word) > $maxlength)
  {
   $length = length($word);
   $offset = 0;
  
   while ($offset+$maxlength <= $length){
    $tmp = substr($word,$offset,$maxlength);
    $newvals .= "$tmp-<br>";
    $offset += $maxlength;
   }
 
   if ($last = substr($word,$offset)){$newvals .= "$last ";}
 
  }else{
   $newvals .= "$word ";
  }
 }
 return $newvals;
}
1;