while ( $sth->fetch() ) { chomp $x; if ( $x =~ /^foo/ ) { print "$x\n"; last; } } #### my ($count) = $dbh->selectrow_array("SELECT count(*) FROM table WHERE LEFT(colum,3) = 'foo'"); if ($count > 0) { print "Do what you need here"; }