if ($sl =~ m/\n\s*(Subject.*\n)/gm) { $mid=$1; print "1st\n"; } else { if ($sl =~ m/\n\s*(Subject.*\n)/gm) { $mid=$1; print "2nd\n"; } }