in reply to regex for string
I think this can be a easy way interms of using regular expression ,
$_="1and2" ; /^(.).*(.)$/; print "$1 and $2 " ; [download]