$foo = qq{^snafu^|^foobar^\n}; $foo =~ m/\A(\W) # \A instead of ^ and match first non-word [^\1]+? # Match everything that isn't in \1 \1(\W) # Match non-word following the 2nd \1 /xms; $text_qual = $1; $field_sep = $2; print "[$text_qual]\n"; print "[$field_sep]\n"; #### [^] [|]