#!/usr/bin/perl use strict; sub parenth { my ($string) = (@_); my $l_count = () = ($string =~ /\(/g); my $r_count = () = ($string =~ /\)/g); if ($l_count != $r_count) { print "There is no balance on this line ($l_count vs $r_count)! Did you format it correctly???"; return 0; } else { print "There is balance in this universe"; return 1; } } my $test_string = 'x = (89 - 12)*( 1 + 2)'; parenth($test_string);