my $pat = qr/\w+ ((w)hite|(b)lack)/; $_ = 'mostly black'; print "$1 starts with $+\n" if /$pat/; $_ = 'but some white spaces'; print "$1 starts with $+\n" if /$pat/;