in reply to Reading a File by Line then Analyzing each Line

i dont know if this example could help you any

# File containing Q&A my $file = 'Q.txt'; open(FH,$file) or die $!; while (my $line = <FH>) { if ($line =~m/^\d+\./) { print "Question : $line"; }else{ print $line; } } close(FH);

Update : if you want to remove "*" from the end just add the following line after the while loop

$line =~s/\*$//;