sub duplicate_record { my ($name, $surename) = @_; my $is_duplicate = 0; my $html_title = 'Duplicate records have been found!'; open (DBFILE, "dbfile.pdb") or die("Cannot open file for matching: $!"); local $_; while () { my @pattern_check = split(/,/, $_); #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; $is_duplicate = 1; last; } } close (DBFILE); save_db() unless $is_duplicate; }