use strict; use warnings; #Use M302 S235 with the fan on and off, putting the values into the variables below my $PFanOn = "P071.98"; my $PFanOff = "P037.04"; my $IFanOn = "I008.14"; my $IFanOff = "I001.79"; my $DFanOn = "D159.21"; my $DFanOff = "D191.75"; open (MYFILE, '>MultiplePID.gcode'); # read stdin and any/all files passed as parameters one line at a time while (<>) { chomp; my $input = $_; print MYFILE "$input\n"; if ($input =~ m/M106/) { print MYFILE "M301 $PFanOn $IFanOn $DFanOn\n"; } elsif ($input =~ m/M107/) { print MYFILE "M301 $PFanOff $IFanOff $DFanOff\n"; } } close(MYFILE);