in reply to help me to find out the error??

This is a somewhat shorter version, using a dispatch table (drawing some bits and pieces from your and marto's code).
#!/usr/bin/perl use strict; use warnings; print"###simple calculator program##\n\n"; my $opt2 = "y"; my %operations = ( "+" => sub { return $_[0] + $_[1]}, "-" => sub { return $_[0] - $_[1]}, "*" => sub { return $_[0] * $_[1]}, "/" => sub { return $_[0] / $_[1]} ); while ($opt2 eq "y"){ print "enter the first number\n"; chomp( my $num1 = <> ); print "enter the second number\n"; chomp( my $num2 = <> ); print "enter your option\n\+ for addition\n\- for subtraction\n\* +for multiplication\n\/ for divison\n option:"; chomp(my $opt = <>); print "you have entered wrong option\n" and next unless defined $o +perations{$opt}; print "you pressed the $opt key\n"; print $operations{$opt}->( $num1, $num2), "\n\n"; print "do you want to continue press y or n?\n"; chomp ($opt2 =<>); }
The good thing about this technique is that if you want to add an operation, say exponentiation, you only need to add one single line of code in the dispatch table (well, plus one line in your menu option). In addition, the return statement is not needed in the subs defined in the dispatch table (a function returns the last evaluated expression), so that the dispatch table could be:
my %operations = ( "+" => sub { $_[0] + $_[1]}, "-" => sub { $_[0] - $_[1]}, "*" => sub { $_[0] * $_[1]}, "/" => sub { $_[0] / $_[1]}, "**" => sub { $_[0] ** $_[1]} );
.