#!/usr/bin/env perl use Modern::Perl; my $line = '>foo# bar'; if( $line =~ /^>(\w+)\s(.+)$/ ){ say "Found word $1"; } else { say "No match."; } #### $line =~ /^>(\w+)/; # capture as many consecutive \w characters as possible following > $line =~ /^>(\S+)/; # capture as many consecutive non-whitespace chars as possible following >