#!/usr/bin/perl -w my (@line, $brack, $diff, $num); while (<>) { $num++; if ($diff = y/{/{/ - y/}/}/) { $brack += $diff; $line[$brack] = $num if ($diff > 0); } } print ($brack > 0 ? "Error at line $line[$brack]?\n" : "No bracket errors found.\n");