my $line=' this or that '; my @patterns= ( $line =~ /\s*(\S*)\s*(\S*)\s*(\S*)/ ); print join('-',@patterns); # prints this-or-that