For this purpose, you want the text of the error message as much as the timestamp, to know if the error is the same or different. That should be relatively simple. The question would be how to enforce the time window.
Two approaches suggest themselves to me. First, store the timestamp and error message in a file. The next time your script runs, read the timestamp from that file and compare to the current time. This will involve learning how to convert strings into a scalar (or object) representing time. There are CPAN modules to help with this; Time::Piece is the first one I found using a simple search. This would be useful skill to have, and in my opinion worth the effort.
However, a simpler approach would be to write just the error message out to a file (so you can compare it to the next message), and treat the create date of the file as the timestamp. It should be reasonably close to the actual error timestamp (worst case plus the running time interval of your script). And, you can use the -M operator which returns the age of the file in days to determine if it has been 30 minutes or not since you last saw that error.
use strict;
use warnings;
my $window = 30.0 / 1440; # 30 minutes
my $error_file = 'error.txt';
my $error_message = shift;
chomp($error_message);
if (! -e $error_file) {
# generate warning and then
write_error_file();
} else {
chomp(my $old_error = `cat $error_file`);
# two conditions warrant a warning
# a) either a new type of error or b) it has been
# more than 30 minutes since we last saw this one
if (($old_error ne $error_message) || (-M $error_file > $window)) {
# generate warning and then
write_error_file();
}
}
sub write_error_file {
my $ofh;
print "New error $error_message\n";
open $ofh,'>',$error_file;
print $ofh $error_message;
close $ofh;
}