use strict; use warnings; while () { if (/^(\d+\D\d)_(LacZ|pgK|SD|SU)(.*)$/) { print "match: $_"; print ' $1', " is $1\n"; print ' $2', " is $2\n"; print ' $3', " is $3\n"; } else { print "no match: $_"; } } __DATA__ 12774L1_LacZ.SEE.rc_C06_2008-12-01.ab1 12774L1_pgK.Neo.2fw_D06_2008-12-01.ab1 12774L1_SD_B06_2008-12-01.ab1 12774L1_SU_A06_2008-12-01.ab1 foo.bar