if input_name is in list: print "valid" else: print "not valid" This could be implemented with the following code: if (grep(/^$input$/, @names) { print "Valid\n"; } else { print "Not valid\n"; }