my $pattern = qr/ (?: # Match beginning of line or whitespace separator, no capture \A | \s+ ) ( # Capture one of: "[^"]*" # Matched double quotes | '[^']*' # Matched single quotes | {[^}]*} # Matched curly brackets | \S+? # non whitespace ) (?= # Match end of line or whitespace separator, positive lookahead,no capture. \z | \s+ ) /x; my $data = '#VER "" 3 19950101 "Overforing BG till PG" 19950608'; my @values = $data =~ /$pattern/g; for my $i (0..$#values) { printf "%2d) %s\n",$i,$values[$i]; }