#!/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 $operations{$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 =<>); }