use strict; use warnings; use Data::Dumper; open FH,") { #reading line from a file one by one if(/\*[^*]+\*/) { #checking whether the line has two *'s in it push @arr1,$_ ; #pushing that line to an array1 } else { push @arr2,$_; #pushing that line to an array2 if it isn't having two *'s in it } } close FH; #closing the file handle print "Lines with two *'s in it\n"; print @arr1; print "Lines with two *'s in it\n"; print @arr2;