As evidenced by the varied responses from the other monks, your problem statement is somewhat unclear.
Perhaps this is what you're looking for?
#!/usr/bin/env perl
use warnings;
use strict;
while (my $myvar=<DATA>) {
chomp($myvar);
if ($myvar=~/^([A-Z])\1*$/) {
print "'$myvar' matches\n";
}
else {
print "'$myvar' doesn't match\n";
}
}
__DATA__
X
XXXX
XXXY
XXYX
YXXX
AAAA
BBBB
BBBC
DDD4
Output:
'X' matches
'XXXX' matches
'XXXY' doesn't match
'XXYX' doesn't match
'YXXX' doesn't match
'AAAA' matches
'BBBB' matches
'BBBC' doesn't match
'DDD4' doesn't match