sub foo { my $str = shift; my @text = $str =~ /(\S+)/g; ... } # call as foo("This is a test");