in reply to Re^3: Output in variable
in thread Output in variable

Just use concatenation if you want to capture all the lines.
my $output; $PatternToMatch="^SELECT"; $tmpfile="pattern.txt"; open(MYFILE, "$tmpfile")|| die "Cannot create $tmpfile\n"; while (<MYFILE>) { if (/$PatternToMatch/) { #print "$_"; $output .=$_; } }