in reply to if statement not working

Just a small change in your code if ( $_ == "aaaa" ) , you are comparing characters so it should be if ( $_ eq "aaaa" ) Now it should work.