use strict; use warnings; while () { if (/^S\s+(?:\-?\d+(?:\.\d+)?\s+){2}\(\s?(?:(INOUT|OUTPUT))\s?\)/) { print "Matched:$_"; } else { print "Did NOT match:$_"; } } __DATA__ onn (bbcreccsnnl_output) !OUTPUT S 0.0 0.0 (OUTPUT) A 0.0 0.0 (OUTPUT) S 1 4 5 (OUTPUT) S 35 -27 ( INOUT ) S -26.95 32.73 (OUTPUT )