# suppose %product_id has the "PSLA0L00U00E"-like strings from the DB # as hash keys, and something useful (row_ids?) as hash values... open( REJ, ">", "merchant_data.to_review" ) or die $!; while () { # reading merchant stuff line-by-line my $orig = $_; s/\W+//g; for my $model ( keys %product_id ) { if ( index( $_, $model ) >=0 ) { handle_a_match( $orig, $model ); $orig = ''; last; } # if the last character of $model is "optional", then # use this else block: else { chop ( my $modl = $model ); if ( index( $_, $modl ) >= 0 ) { hanle_a_match( $orig, $model ); $orig = ''; last; } } } print REJ $orig unless ( $orig eq '' ); } #### else { my $modelrgx = $model . "?"; # make last character "optional" $modelrgx =~ s/[1Il]/[1Il]/g; $modelrgx =~ s/[0O]/[0O]/g; if ( /$modelrgx/ ) { handle_a_match( $orig, $model ); $orig = ''; last; } }