while ( $sth->fetch() ) { chomp $x; if ( $x =~ /^foo/ ) { print "$x\n"; last; } }