in reply to regex for string
Have a look at perlre, in particular at the zero-width assertions \A and \z (lower-case z!), and to the meta-character . (dot). But I think that you can easier extract the characters using substr.