use strict; use warnings; FindInHorizontalRegion('SETTINGS:Flight','SETTINGS:Tick','1000',10); #FindInHorizontalRegion('Flight','SETTINGS:Tick','1000',10); sub FindInHorizontalRegion { print "Inside FindInHorizontalRegion \n" ; my ( $element1,$element2,$duration,$threshold) = @_; my $regex1 = '(.*?)\:(.*?)' ; print "The first element is $element1 \n....The second element is $element2 \n... Entering if condition for the first time to check if it is text or image \n"; if ( $element1 =~ m/$regex1/g ) { print "The regex is matched and the first element is an image\n"; } else { print "THe first element is text \n"; } if ( $element2 =~ m/$regex1/g ){ print "The second element is an image \n"; } else { print "THe second element is text \n"; } print "Horizontal coordinates obtained \n"; if ( $element1 =~ m/$regex1/g) { print "To check for Image \n"; } else { print "To check for Text \n"; } }