#!/usr/bin/perl -p0777 -i.org my $parser; BEGIN { $parser= qr{ \G # Don't skip anything ( [^'"/]+ # Stuff we don't care about | '(?:[^\\']+|\\.)' # '"', '\'', '\\', 'param' | /\* .*? \*/ # A C comment | //[^\n]+ # A C++ comment | / # /, not a comment, division | "((?:[^\\"]+|\\.)*)" # A quoted string ($2) | (.) # An error ($3) ) # Entire match ($1) }xs; } s{$parser}{ if( defined $3 ) { my $char= $2; my $pos= pos($code)-5; $pos= 0 if $pos < 0; my $context= substr( $code, $pos, 10 ); warn "Ignoring unexpected character ($char) in ($context)"; } if( defined $2 ) { my $string= $2; #... manipulate $string ... $string; } else { $1; } }g;