I would have written the above logic like this
#!/usr/local/bin/perl
use strict;
use warnings;
my $input;
my $hrate = 0;
my $yrate = 0;
while (!defined $input) {
print "\nDo you wish to calculate yearly salary (y) or hourly rate
+ (h)?";
chomp ($input = <STDIN>);
if ($input =~ /h/i) {
print "\nEnter your yearly salary:";
chomp ($yrate = <STDIN>);
$hrate = ($yrate / 52) / 40;
print "\nYour hourly rate is $hrate";
}elsif ($input =~ /y/i) {
print "\nEnter your hourly rate:";
chomp ($hrate = <STDIN>);
$yrate = ($hrate * 40) * 52;
print "\nYour yearly salary is $yrate";
}elsif ($input =~ /q/i) {
exit;
}else {
print "\nError in input";
}
undef $input; #to continue in the loop
}
I would like to suggest that a good place to start learning Perl is to read "Learning Perl", published by O'Reilly & Associates. And one more book is freely available online. Name is Simon Cozens'
Beginning Perl.