#!/usr/bin/perl -w use strict; use warnings; my $suchwort = 'daten'; foreach my $code ( <<'heredoc' $a = 'b'; # Kommentar mit Suchwort daten heredoc , <<'heredoc' $a = 'daten'; heredoc , <<'heredoc' #$a = 'daten'; heredoc , <<'heredoc' #$a = 'daten'; heredoc , ) { my $quoted = quotemeta $suchwort; if ($code =~ m/^.*$quoted/) { print $code . "matcht und ist " . ($code =~ m/^[^#]*$quoted/ ? 'aktiv' : 'auskommentiert') . "\n\n"; } }