Serial Comms - Win7-Arduino in Perl

I am trying to control a stepper motor using a PerlTk GUI but I can't get serial comms to work either direction between my 64bit Win laptop and a Nano. Comms work fine with the serial monitor in the Arduino IDE.
I've created a simplified example to try to get things working:
On the Arduino:

bool toggle = HIGH;

void setup() {
  digitalWrite(LED_BUILTIN, toggle);

void loop() {

void serialEvent(){
  char cmd =;
  Serial.print("Received ");
  Serial.println( cmd );
  while(Serial.available()){;} // clean junk fm input buffer
  toggle = !toggle;
  digitalWrite(LED_BUILTIN, toggle);

And this works perfectly using the serial monitor in the Arduino IDE.
So I run the following on the PC:

use Win32::SerialPort;
my $port = Win32::SerialPort->new("COM11");
print "Port opened.\n";

$port->baudrate(9600) || die "Failed setting baud"; # Configure this to match your device
$port->databits(8) || die "Failed setting databits";
$port->parity("none") || die "Failed setting parity";
$port->stopbits(1) || die "Failed setting stopbits";
print "Settings done.\n";

$port->write_settings() || die "Failed writing settings";
print "Settings written\n";

print "An F written.\n";

while (1) {
    my $char = $port->lookfor();
    if ($char) {
        print "Received character: $char \n";
    sleep (1);
    print "Sleeping\n";

None of the die statements get called, all the debug prints print but the Arduino never toggles the LED or sends a response (at least I never see one.) This is using Strawberry Perl I've tried working through Win32::SerialPort - User interface to Win32 Serial API calls - but what I can understand hasn't helped. And none of the other (generally quite old) ideas that I can find online help.
Can somebody help, please and thanks?


I've never looked at Perl. You are aware that the Arduino is reset when you open the serial port? And that it takes a few seconds before your sketch runs?

In setup(), first print something on Serial and let your Perl code receive that before starting to send data from Perl to Arduino.

A test can be to continuously send something from Perl to the Arduino; the RX led on the Arduino should be flashing constantly. If not, your Perl setup is wrong.

Likewise I have no experience of Perl. This Python - Arduino demo may help. It should work on Windows with an appropriate change to the serial port references.