use strict; use warnings; use Switch; open (FILE, shift)||die $!; while(){ switch ($.) { case 1 { (m/^12345.67890$/) ? (print "Line $. \"$&\" Matched\n") : (print "Line $. Not Matched\n"); } case 2 { (m/^13456.12345$/) ? (print "Line $. \"$&\" Matched\n") : (print "Line $. Not Matched\n"); } case [3..5]{ (m/^\d+$/) ? (print "Line $. \"$&\" Matched\n") : (print "Line $. Not Matched\n"); } } } close(FILE); #### Input is: (test.txt) 12345.67890 13456.12345 12A345.67890 13E456.12345 12B345.67890 Output is: Line 1 "12345.67890" Matched Line 2 "13456.12345" Matched Line 3 Not Matched Line 4 Not Matched Line 5 Not Matched