my $regexp = qr/ (?: ( int | char | bool | long ) ) /x; if ($string =~ /\A $regexp \z/xms){ print $&, "\n"; }