my $datafile = '/etc/postfix/virtual'; =pod # This bits a mess? # First you composite the username and domain together my $req_addr = "$username\@$domain"; # Then you use a very iffy regex to break them apart? my ( $name, $domain ) = $req_addr =~ /^([\w.-]+)(@[\w.-]+)$/ ; =cut # so assuming that $name and $domain contain the right information my ($line, $mark, $rest); open FH, "+<$datafile" or die "Open $main::FH failed; $!\n"; #1 $line = while $line !~ /^$domain$/o; #2 $mark = tell(FH), $line = while $line =~ /$domain/o; #3 @rest = ($line, ); #4 truncate( FH, $pos ); #5 print FH "$name\@$domain\t$name\n"; #6 print FH "@rest"; #7 close FH or die warn "Error closing $main::FH; $!\n"; #8