#!/usr/bin/perl use Win32::SerialPort; $PortObj->are_match("abcd"); # Pattern to match my $gotit = ""; until ("" ne $gotit) { $gotit = $PortObj->lookfor(); # Look for the pattern "abcd" in the incoming data if($gotit){last;} # to exit the loop after the pattern detection print("Pattern is not detected\n"); # print the message till pattern is detected. # send some command through serial port in loop till the pattern is detectd } # send next command after the pattern detection.