print "yahoo!\n" if grep /^#/ , @lines; # or for ( @lines ) { if ( /^#/ ) { print "yahoo!\n"; last; } }