in reply to need to consolidate two lines to one

Perl is a free-form language, so you can actually write them on one line (although I don't see any sense in it):
$string = "hello"; $string =~ /^\s+|\s$/g;

Also since "hello" is a literal that contains neither leading nor trailing whitespaces, you can actually just write that as

$string = "hello";
If you have the string in a variable, you can write:
($string = $source) =~ s/^\s+|\s$/g;