while (my $input = <$sock>) { print "input line: **start**$input**end**\n"; # debugging if (index($input, "/QUOTE") != -1) { print " is a match\n"; # debugging my $str = $input; ($pass) = $str =~ m{/QUOTE\sPASS\s(.*?)$}; print $sock "QUOTE PASS $pass\r\n"; } else { print " not a match\n" # debugging } }