while ( ) { if ( $_ =~ /$MAL/i ) { # Grab all strings that contain this regex # Save them all in $out print OUT $_; }