foreach my $line (@data) { #Work to be done on each line of the file $file_data .= $line if ( $line =~ /\S/ ); }