# ... if ( ($line =~ /notice/) && ($line =~ /rdy/) ) # Spaces to commas $line =~ s/ /,/g; # Get rid of "notice", "[", "mpmstats:", and tabs inside the line. $line =~ s/notice|\[|mpmstats:|\t//g; # Change the dreaded Triple Comma into the nice and smooth Single Comma. $line =~ s/,,,/,/g; # Or even the following if you want to replace all multiple subsequent commas by # just one: # $line =~ s/,,+/,/g; # Show me what I've got print $line; }