#!/usr/bin/perl -w use strict; use warnings; # Hex Zeichen # 22 " # 27 ' my $string = "'VAL1','VAL2',\"VALX\""; $string = "\"\""; my $char_quotes = "[\x22\x27]"; my $count = 0; my $first = 0; my $last = 0; my $position = 0; $count = count_occurrence ($string, $char_quotes); print "count<$count> of <$char_quotes> in <$string>\n"; my $string_out = $string; my $cnt_qu_str = 1; # Nur wenn mehrere Quotes gefunden wurden => Löschen if ( $count > 2 ) { ( $first, $last ) = find_str_pos ( $string ); print "first: $first\n"; print "last: $last\n"; while( $string =~ m/[\x22\x27]/g) { $position = pos( $string ); if ( ( $position != $first ) && ( $position != $last ) ) { # Information print substr( $string, $position - 1 , 1 ) . "\n"; # Löschen if (substr($string_out, $position - $cnt_qu_str , 1 ) =~ $char_quotes ) { substr($string_out, $position - $cnt_qu_str , 1 ) = ""; ++$cnt_qu_str ; } } } print "Test-Ausgabe: $string_out\n"; } sub find_str_pos { # Regex to search for substring # using m modifier my ($str) = @_; my $pos_c_str = 0; my $first_c_pos = 0; my $last_c_pos = 0; my $count_str_qu = 0; while( $str =~ m/[\x22\x27]/g) { # Finding the pos_c_str of substr # using pos() function $pos_c_str = pos($str); if (++$count_str_qu == 1) { $first_c_pos = $pos_c_str; # print "$count\n"; } else { $last_c_pos = $pos_c_str; } # print "$pos_c_str\n"; } return ( $first_c_pos, $last_c_pos ); } sub count_occurrence{ my ($str, $char_quote) = @_; my $count_qu = 0; my $len = length($str); $str =~ s/$char_quote//g; my $len_new = length($str); $count_qu = $len - $len_new; return $count_qu; }