you can indicate the beginning of a string with \A and the end of a string with \Z. ^ matches the beginning of lines, and $ matches the end of lines. so you could use something like /^user1$/ or /\Auser1\Z/. of course, if you just want an exact match, you can always use $var eq 'user1'.