http://qs321.pair.com?node_id=1084789


in reply to Check if a variable contains only one letter?

You should say "it contains X from the beginning to the end":
$myvar =~ /^X+$/;

Update: Be careful as "XXXX\n" also matches, so you might need to chomp first.

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Check if a variable contains only one letter?
by tobyink (Canon) on May 02, 2014 at 22:59 UTC

    Regarding your update, just use /\AX+\z/.

    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
Re^2: Check if a variable contains only one letter?
by DrHyde (Prior) on May 06, 2014 at 10:38 UTC

    Or if you don't know what the letter is ...

    if($myvar =~ /^([A-Za-z])\1*$/) { ... }

    That is, match the beginning of the string, then any letter, then any more of that same letter, then the end of the string. Adapt as appropriate for Unicode abominations.