while() { if( $_ =~ /(foo)/ ) { print "$count: $1 -- $&\n"; $count ++; } }