In addition to the other comments, there are some problems with your regex. This will not match, for instance, because the # character isn't matched by either \w or \s:
#!/usr/bin/env perl use Modern::Perl; my $line = '>foo# bar'; if( $line =~ /^>(\w+)\s(.+)$/ ){ say "Found word $1"; } else { say "No match."; }
So it depends on what you mean by a "word." If you mean just characters matched by \w, then the opposite of that is \W. If you mean "non-whitespace," you should be using \S to match that. Also, that match is greedy, so there's no need to follow it with an opposite match in the first place. These will work just fine, and be much more legible:
$line =~ /^>(\w+)/; # capture as many consecutive \w characters as p +ossible following > $line =~ /^>(\S+)/; # capture as many consecutive non-whitespace char +s as possible following >
Aaron B.
My Woefully Neglected Blog, where I occasionally mention Perl.
In reply to Re: Grep 1st word of strings in array
by aaron_baugher
in thread Grep 1st word of strings in array
by imtakinbioinformatic
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |