in reply to Dot star okay, or not?

Well I think .* is ok in your case.
Maybe you can do it by:
$text=~s/(^\s*|\s*$)//g;
Then you do not need to store the 'middelthing'. This might be quicker, but I don't know this exactly. Anyway it works :)
----------------------------------- --the good, the bad and the physi-- -----------------------------------