my $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 ($1) | (.) # An error ($2) ) }xs; my $code= do { local($/); }; my @strings; while( $code =~ m/$parser/g ) { if( defined $1 ) { push @strings, $1; } elsif( defined $2 ) { 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)"; } }