#!/usr/bin/perl use strict; use warnings; my $wanted = 'coucou'; while (my $line = ) { chomp($line); my $rest = ''; if ($line =~ m/$wanted(.*)$/) { $rest = $1; print "$wanted:$rest\n"; } else { print "$wanted not found in $line\n"; } } __DATA__ abc coucou def not in this line in this line, but nothing following coucou coucou once, coucou twice, coucou three times - what should be done with this line?