sub duplicate_record {
my $html_title = 'Duplicate records have been found!';
die("Cannot open file for matching\n") unless open (DBFILE, "dbfile.pdb");
while ( and $found == 0) { #while not eof file and pattern not matched ($found == 0)
foreach $record () { #foreach line ($record)
@pattern_check = split(/,/, $record); #spit line where you see comma (,) ($record)
if ($name eq $pattern_check[0] and $surename eq $pattern_check[1]) { #check if duplicate is available
print $cgi-> start_html("$html_title").
$cgi-> h1('Duplicate records:').
$cgi-> p("$name $surename $phone already exists.\nGo back and fill something else than that!").
$cgi-> end_html;
$found = 1;
}#if
}#foreach
}#while
close (DBFILE);
if ($found == 0) {
save_db();
}#if
}# sub duplicate_record