while(){ my $orig = $_; if ( s/foo\@there\.com/bar\@here\.com/ ) { print "< $orig> $_\n"; } } __DATA__ foo@there.com john.foo@there.com foo@there.com.au Mr Foo #### < foo@there.com > bar@here.com < john.foo@there.com > john.bar@here.com < foo@there.com.au > bar@here.com.au < Mr Foo > Mr Foo #### s{([a-zA-Z_\.]+\@[a-zA-Zz\.\-]+)} {$1 eq $old ? $new : $1}ge