use strict; use warnings; my $move = "Qe4++"; #reverse as per dragonchild's suggestion my @parsed = reverse split //, $move; print join('', @parsed) . "\n"; my $check; my $row; my $col; my $piece; #convert the letters into appropriate numbers #there is probably a faster way to to this my %col_convert = (a => 0, b => 1, c => 2, d => 3, e => 4, f => 5, g => 6, h => 7); foreach my $elem (@parsed) { #check for, well, check if($elem eq '+') { #start the process to see if this is a checkmate my $nextElem = shift @parsed; print "nextElem $nextElem" . "\n"; #if it is then print if($nextElem eq '+') { print "Checkmate\n"; next; } else { #otherwise put it back on the stack for the next #iteration unshift @parsed, $nextElem; } #then print check in this instance print "Check\n"; }elsif($elem =~ m/[1-8]/) { $row = $elem; print "Row: $row\n"; }elsif($elem =~ /[a-h]/) { #convert to number $col = $col_convert{$elem}; print "Col: $col\n"; }elsif($elem =~ m/x/) { #this is a capture to that square print "Capture on $col $row\n"; }elsif($elem =~ /[KQRNB]/) { $piece = $elem; print "Piece to move is $piece\n"; } else { die "not a valid move\n"; } }