#!/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 , <<'heredoc' print "#".datensub()."/n"; # Sonderfall, der muss nicht richtig matchen! heredoc , ) { my $quoted = quotemeta $suchwort; if ($code =~ m/$quoted/) { print $code . "matcht und ist " . ($code =~ m/^\s*\#/ ? 'auskommentiert' : 'aktiv') . "\n\n\n\n"; } }