#! perl use strict; use warnings; while () { print "$1.$2\n" if m{ ^ \s* Pin: \s* ([^.]*?) \. (\S*) (?: \s+ out)? $ }x; } __DATA__ Pin: U343.IN1 in Pin: U713.INP out Pin: U714.QN