in reply to how to shorten given string?

/^(.{1, 20}).*/; $shortened_string = $1;
but that doesn't work?
That should work, though the .* is useless and you ought to make sure the match succeeds before using $1: $shortened_string = /^(.{1,20})/ && $1; or even skip using $1 at all: ($shortened_string) = /^(.{1,20})/; (though the match can only fail if the string is empty or undef.)  Go back and try it again and make sure that you didn't have something else wrong to make it appear not to work.