use Strict; use IO::Socket; use IO::Select; my $COMport=33; #open Port or die if blocked / wrong port if (!open( PORT, "+>\\\\.\\COM$COMport" )) { die ("Can't open COM$COMport"); } PORT->autoflush(1); PORT->flush(); print "\nEnter AT command:"; my $ATcmd=; chomp($ATcmd); # remove CRLF $ATcmd =~ s/^\s+//; # remove leading space $ATcmd =~ s/\s+$//; # remove trailing space print "Sending: '$ATcmd'\n"; print PORT $ATcmd . "\r\n"; sleep(2); #Reading the response print "reading\n"; while (1) { my $ret=; print $ret; if ($ret=~/^OK/ || $ret=~/^ERROR/) { last} } close(PORT); print "done!";