while () { chomp; last if $_ eq ']'; # It's also possible to do "last if /^\]$/", but # all you need is a simple string compare. # do stuff }