use warnings; $logfile="log.txt"; $error="DOWN"; $warn="PROBLEM"; $redbutton="\"; $greenbutton="\"; $yellowbutton="\"; open LOG, $logfile or die "Cannot open $logfile for read :$!"; my $button = $greenbutton; while () { if ($_ =~ /$error/i) { $button = $redbutton; print "\n\n"; print "$redbutton"; } if ($_ =~ /$warn/i) { $button = $yellowbutton; print "\n\n"; print "$yellowbutton"; } } close LOG;